Пример #1
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)
			}
		}
	}
}
Пример #2
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
}
Пример #3
0
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(os.Args[1], dns.TypeMX)
	m.MsgHdr.RecursionDesired = true

	// Simple sync query, nothing fancy
	r := c.Exchange(m, config.Servers[0])

	if r == nil {
		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)
	}
}
Пример #4
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(os.Args[1], dns.TypeDNSKEY)

	// Set EDNS0's Do bit
	e := new(dns.RR_OPT)
	e.Hdr.Name = "."
	e.Hdr.Rrtype = dns.TypeOPT
	e.SetUDPSize(2048)
	e.SetDo()
	m.Extra = append(m.Extra, e)

	c := dns.NewClient()
	r := c.Exchange(m, conf.Servers[0])
	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)
	}
	// Stuff must be in the answer section, check len(r.Answer)
	for _, k := range r.Answer {
		// Foreach key would need to provide a DS records, both sha1 and sha256
		if key, ok := k.(*dns.RR_DNSKEY); ok {
			key.Hdr.Ttl = 0
			ds := key.ToDS(dns.SHA1)
			fmt.Printf("%v\n", ds)
			ds = key.ToDS(dns.SHA256)
			fmt.Printf("%v\n", ds)
			ds = key.ToDS(dns.SHA384)
			fmt.Printf("%v\n", ds)
		}
	}
}
Пример #5
0
// Get the key from the DNS (uses the local resolver) and return them.
// If nothing is found we return nil
func getKey(name string, keytag uint16, server string, tcp bool) *dns.RR_DNSKEY {
	c := dns.NewClient()
	if tcp {
		c.Net = "tcp"
	}
	m := new(dns.Msg)
	m.SetQuestion(name, dns.TypeDNSKEY)
	r, err := c.Exchange(m, server)
	if err != nil {
		return nil
	}
	for _, k := range r.Answer {
		if k1, ok := k.(*dns.RR_DNSKEY); ok {
			if k1.KeyTag() == keytag {
				return k1
			}
		}
	}
	return nil
}
Пример #6
0
func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
	dns.HandleQueryFunc(os.Args[1], qhandler)
	dns.ListenAndQuery(nil, nil)

	m4 := new(dns.Msg)
	m4.SetQuestion(os.Args[1], dns.TypeA)
	m6 := new(dns.Msg)
	m6.SetQuestion(os.Args[1], dns.TypeAAAA)
	c.Do(m4, conf.Servers[0]) // Also 1 and 2 (and merge the results??
	c.Do(m6, conf.Servers[0])

	var ips []string
	i := 2 // two outstanding queries
forever:
	for {
		select {
		case r := <-dns.DefaultReplyChan:
			if r[1] != nil && r[1].Rcode == dns.RcodeSuccess {
				for _, aa := range r[1].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
}