Exemple #1
0
func main() {
	// this is your domain. All records will be scoped under it, e.g.,
	// 'test.docker' below.
	ds := dnsserver.NewDNSServer("docker")

	// set an A record. RRs are not supported.
	ds.SetA("test", net.ParseIP("127.0.0.2"))
	ds.SetA("test2", net.ParseIP("127.0.0.3"))

	// Set a SRV record. The host values will be qualified for you with the
	// domain you provide.
	ds.SetSRV("test", "tcp", []dnsserver.SRVRecord{
		{Port: 80, Host: "test"},
		{Port: 443, Host: "test"},
	})

	if len(os.Args) > 1 {
		if err := ds.Listen(os.Args[1]); err != nil {
			panic(err)
		}
	} else {
		if err := ds.Listen("127.0.0.1:53"); err != nil {
			panic(err)
		}
	}
}
Exemple #2
0
func main() {
	kingpin.Parse()

	dns = dnsserver.NewDNSServer(*cliDomain)

	wg := &sync.WaitGroup{}

	wg.Add(1)
	go func() {
		log.Info("Starting the DNS server on " + *cliListen)

		if len(os.Args) > 1 {
			if err := dns.Listen(os.Args[1]); err != nil {
				panic(err)
			}
		} else {
			if err := dns.Listen(*cliListen); err != nil {
				panic(err)
			}
		}

		wg.Done()
	}()

	wg.Add(1)
	go func() {
		log.Info("Receiving records on port " + *cliPort)
		s := &http.Server{
			Addr:    ":" + *cliPort,
			Handler: http.HandlerFunc(receive),
		}
		s.ListenAndServe()
		wg.Done()
	}()

	wg.Wait()
}