Пример #1
0
func main() {
	cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
	printf = flag.Bool("print", false, "print replies")
	flag.Usage = func() {
		flag.PrintDefaults()
	}
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	dns.HandleFunc(".", handleReflect)
	go serve("udp4")
	go serve("udp6")
	go serve("tcp4")
	go serve("tcp6")
forever:
	for {
		select {
		case <-signal.Incoming:
			fmt.Printf("Signal received, stopping\n")
			break forever
		}
	}
}
Пример #2
0
func main() {
	dns.HandleFunc(".", handleReflect)
	go serve("udp4")
	go serve("udp6")
	go serve("tcp4")
	go serve("tcp6")
forever:
	for {
		select {
		case <-signal.Incoming:
			fmt.Printf("Signal received, stopping\n")
			break forever
		}
	}
}
Пример #3
0
func main() {
	listen := flag.String("listen", "127.0.0.1:8053", "set the listener address")
	server := flag.String("server", "127.0.0.1:53", "remote server address(es), seperate with commas")
	verbose = flag.Bool("verbose", false, "Print packet as it flows through")
	//	cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
	flag.Usage = func() {
		flag.PrintDefaults()
	}
	flag.Parse()
	/*
		if *cpuprofile != "" {
			f, err := os.Create(*cpuprofile)
			if err != nil {
				log.Fatal(err)
			}
			pprof.StartCPUProfile(f)
			defer pprof.StopCPUProfile()
		}
	*/

	clients := strings.Split(*server, ",")
	qr = make([]*FunkClient, len(clients))
	for i, ra := range clients {
		qr[i] = new(FunkClient)
		qr[i].Client = dns.NewClient()
		qr[i].Addr = ra
	}

	f = NewFunkenSturm()
	ok := f.Setup()
	if !ok {
		println("Setup failed")
		return
	}

	dns.HandleFunc(".", serve)
	go listenAndServe(*listen, "tcp")
	go listenAndServe(*listen, "udp")

forever:
	for {
		select {
		case <-signal.Incoming:
			println("Signal received, stopping")
			break forever
		}
	}
}
Пример #4
0
func main() {
	cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
	printf = flag.Bool("print", false, "print replies")
	compress = flag.Bool("compress", false, "compress replies")
	tsig = flag.String("tsig", "", "use MD5 hmac tsig: keyname:base64")
	var name, secret string
	flag.Usage = func() {
		flag.PrintDefaults()
	}
	flag.Parse()
	if *tsig != "" {
		a := strings.SplitN(*tsig, ":", 2)
		name, secret = a[0], a[1]
	}
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	dns.HandleFunc(".", handleReflect)
	go serve("tcp", name, secret)
	go serve("udp", name, secret)
	sig := make(chan os.Signal)
	signal.Notify(sig)
forever:
	for {
		select {
		case <-sig:
			fmt.Printf("Signal received, stopping\n")
			break forever
		}
	}
}
Пример #5
0
func main() {
	debug = flag.Bool("debug", false, "enable debugging")
	cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	file, err := os.Open("miek.nl.signed")
	defer file.Close()
	if err != nil {
		fmt.Printf("%s\n", err.String())
		return
	}
	p := dns.NewParser(bufio.NewReader(file))
	zone, err = p.Zone()
	if err != nil {
		fmt.Printf("%s\n", err.String())
		return
	}
	s, err := zone.LookupName("miek.nl.", dns.ClassINET, dns.TypeSOA)
	if err != nil {
		fmt.Printf("%s\n", err.String())
		return
	}
	soa = s.RRs[0]

	s1, err := zone.LookupName("miek.nl.", dns.ClassINET, dns.TypeNS)
	if err != nil {
		fmt.Printf("%s\n", err.String())
		return
	}
	ns = s1.RRs
	if len(s1.RRsigs) > 0 {
		nsDNSSEC = ns
		for _, r := range s.RRsigs {
			nsDNSSEC = append(nsDNSSEC, r)
		}
	}

	spam := "Proudly served by Go: http://www.golang.org"
	spamIN = &dns.RR_TXT{Hdr: dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeTXT, Class: dns.ClassINET}, Txt: spam}
	spamCH = &dns.RR_TXT{Hdr: dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeTXT, Class: dns.ClassCHAOS}, Txt: spam}

	dns.HandleFunc("miek.nl.", handleQuery)
	dns.HandleFunc("bind.", handleQueryCHAOS)
	dns.HandleFunc("server.", handleQueryCHAOS)
	go func() {
		err := dns.ListenAndServe(":8053", "udp", nil)
		if err != nil {

		}
	}()
	go func() {
		err := dns.ListenAndServe(":8053", "tcp", nil)
		if err != nil {

		}
	}()
forever:
	for {
		select {
		case <-signal.Incoming:
			fmt.Printf("Signal received, stopping\n")
			break forever
		}
	}
}