Esempio n. 1
0
File: q.go Progetto: Meyermagic/dns
// 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.DNSKEY {
	c := new(dns.Client)
	if tcp {
		c.Net = "tcp"
	}
	m := new(dns.Msg)
	m.SetQuestion(name, dns.TypeDNSKEY)
	m.SetEdns0(4096, true)
	r, _, err := c.Exchange(m, server)
	if err != nil {
		return nil
	}
	for _, k := range r.Answer {
		if k1, ok := k.(*dns.DNSKEY); ok {
			if k1.KeyTag() == keytag {
				return k1
			}
		}
	}
	return nil
}
Esempio n. 2
0
func addresses(conf *dns.ClientConfig, c *dns.Client, name string) (ips []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)
	t := make(chan *dns.Msg)
	defer close(t)
	do(t, c, m4, net.JoinHostPort(conf.Servers[0], conf.Port))
	do(t, c, m6, net.JoinHostPort(conf.Servers[0], conf.Port))

	i := 2 // two outstanding queries
forever:
	for {
		select {
		case d := <-t:
			i--
			if d == nil {
				continue
			}
			if i == 0 {
				break forever
			}
			if d.Rcode == dns.RcodeSuccess {
				for _, a := range d.Answer {
					switch a.(type) {
					case *dns.A:
						ips = append(ips,
							net.JoinHostPort(a.(*dns.A).A.String(), "53"))
					case *dns.AAAA:
						ips = append(ips,
							net.JoinHostPort(a.(*dns.AAAA).AAAA.String(), "53"))

					}
				}
			}
		}
	}
	return ips
}