Exemple #1
0
func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
	m4 := new(dns.Msg)
	m4.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeA)
	m6 := new(dns.Msg)
	m6.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeAAAA)

	addr := make(chan []string)
	defer close(addr)
	c.Do(m4, conf.Servers[0]+":"+conf.Port, addr, qhandler)
	c.Do(m6, conf.Servers[0]+":"+conf.Port, addr, qhandler)

	var ips []string
	i := 2 // two outstanding queries
forever:
	for {
		select {
		case ip := <-addr:
			ips = append(ips, ip...)
			i--
			if i == 0 {
				break forever
			}
		}
	}
	return ips
}
Exemple #2
0
func main() {
	conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	if len(os.Args) != 2 || err != nil {
		fmt.Printf("%s DOMAIN\n", os.Args[0])
		os.Exit(1)
	}
	m := new(dns.Msg)
	m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeDNSKEY)
	m.SetEdns0(2048, true)

	c := new(dns.Client)
	r, _ := c.Exchange(m, conf.Servers[0]+":"+conf.Port)
	if r == nil {
		fmt.Printf("*** no answer received for %s\n", os.Args[1])
		os.Exit(1)
	}

	if r.Rcode != dns.RcodeSuccess {
		fmt.Printf(" *** invalid answer name %s after DNSKEY query for %s\n", os.Args[1], os.Args[1])
		os.Exit(1)
	}
	for _, k := range r.Answer {
		if key, ok := k.(*dns.RR_DNSKEY); ok {
			key.Hdr.Ttl = 0
			for _, alg := range []int{dns.SHA1, dns.SHA256, dns.SHA384} {
				ds := key.ToDS(alg)
				fmt.Printf("%v; %d\n", ds, key.Flags)
			}
		}
	}
}
Exemple #3
0
Fichier : mx.go Projet : h2non/dns
func main() {
	if len(os.Args) != 2 {
		fmt.Printf("%s DOMAIN\n", os.Args[0])
		os.Exit(1)
	}

	// Error checking
	config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
	c := dns.NewClient()

	m := new(dns.Msg)
	m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeMX)
	m.MsgHdr.RecursionDesired = true

	// Simple sync query, nothing fancy
	r, err := c.Exchange(m, config.Servers[0]+":"+config.Port)
	if err != nil {
		fmt.Printf("%s\n", err.Error())
		os.Exit(1)
	}
	if r.Rcode != dns.RcodeSuccess {
		fmt.Printf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
		os.Exit(1)
	}
	// Stuff must be in the answer section
	for _, a := range r.Answer {
		fmt.Printf("%v\n", a)
	}
}
Exemple #4
0
func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
	dns.HandleQueryFunc(os.Args[1], qhandler)
	dns.ListenAndQuery(nil)

	m4 := new(dns.Msg)
	m4.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeA)
	m6 := new(dns.Msg)
	m6.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeAAAA)
	c.Do(m4, conf.Servers[0]+":"+conf.Port)
	c.Do(m6, conf.Servers[0]+":"+conf.Port)

	var ips []string
	i := 2 // two outstanding queries
forever:
	for {
		select {
		case r := <-c.Reply:
			if r.Reply != nil && r.Reply.Rcode == dns.RcodeSuccess {
				for _, aa := range r.Reply.Answer {
					switch aa.(type) {
					case *dns.RR_A:
						ips = append(ips, aa.(*dns.RR_A).A.String()+":53")
					case *dns.RR_AAAA:
						ips = append(ips, "["+aa.(*dns.RR_AAAA).AAAA.String()+"]:53")
					}
				}
			} else {
				fmt.Printf("Nothing recevied for %s\n", name)
			}
			i--
			if i == 0 {
				break forever
			}
		}
	}
	return ips
}