Ejemplo n.º 1
0
func main() {
	c, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
	if len(os.Args) != 2 {
		fmt.Printf("%s DOMAIN\n", os.Args[0])
		os.Exit(1)
	}

	m := new(dns.Msg)
	m.Question = make([]dns.Question, 1)
	d := new(dns.Conn)
	d.RemoteAddr = c.Servers[0]
	for _, a := range addresses(d, os.Args[0]) {
		d.RemoteAddr = a
		if err := d.Dial("udp"); err != nil {
			fmt.Printf("%v\n", err)
			os.Exit(1)
		}

		m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, _ := dns.SimpleQuery("udp", d, m)
		if in != nil && in.Answer != nil {
			fmt.Printf("%v\n", in.Answer[0])
		}
		m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS}
		in, _ = dns.SimpleQuery("udp", d, m)
		if in != nil && in.Answer != nil {
			fmt.Printf("%v\n", in.Answer[0])
		}
	}
}
Ejemplo n.º 2
0
func addresses(d *dns.Conn, name string) []string {
	m := new(dns.Msg)
	m.MsgHdr.RecursionDesired = true //only set this bit
	m.Question = make([]dns.Question, 1)
	var ips []string

	m.Question[0] = dns.Question{os.Args[1], dns.TypeA, dns.ClassINET}
	in, err := dns.SimpleQuery("udp", d, m)
	if in == nil {
		fmt.Printf("Nothing recevied: %s\n", err.String())
		return nil
	}

	if in.Rcode != dns.RcodeSuccess {
		return nil
	}
	// Stuff must be in the answer section
	for _, a := range in.Answer {
		ips = append(ips, a.(*dns.RR_A).A.String()+":53")
	}
	m.Question[0] = dns.Question{os.Args[1], dns.TypeAAAA, dns.ClassINET}
	in, err = dns.SimpleQuery("udp", d, m)
	if in == nil {
		fmt.Printf("Nothing recevied: %s\n", err.String())
		return ips
	}

	if in.Rcode != dns.RcodeSuccess {
		return ips
	}
	for _, a := range in.Answer {
		ips = append(ips, "["+a.(*dns.RR_AAAA).AAAA.String()+"]:53")
	}
	return ips
}
Ejemplo n.º 3
0
func main() {
	c, 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.MsgHdr.RecursionDesired = true //only set this bit
	m.Question = make([]dns.Question, 1)
	m.Question[0] = dns.Question{os.Args[1], dns.TypeDNSKEY, dns.ClassINET}

	d := new(dns.Conn)
	d.RemoteAddr = c.Servers[0]
	in, err := dns.SimpleQuery("udp", d, m)
	if in != nil {
		if in.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
		for _, k := range in.Answer {
			// Foreach key would need to provide a DS records, both sha1 and sha256
			if key, ok := k.(*dns.RR_DNSKEY); ok {
				ds := key.ToDS(dns.HashSHA1)
				ds.Hdr.Ttl = 0
				fmt.Printf("%v\n", ds)
				ds = key.ToDS(dns.HashSHA256)
				ds.Hdr.Ttl = 0
				fmt.Printf("%v\n", ds)
			}
		}
	} else {
		fmt.Printf("*** error: %s\n", err.String())
	}
}
Ejemplo n.º 4
0
Archivo: mx.go Proyecto: elazarl/godns
func main() {
	if len(os.Args) != 2 {
		fmt.Printf("%s DOMAIN\n", os.Args[0])
		os.Exit(1)
	}
	d := new(dns.Conn)
	c, err := dns.ClientConfigFromFile("/etc/resolv.conf")
	// Errorchecking
	d.RemoteAddr = c.Servers[0]

	m := new(dns.Msg)
	m.Id = dns.Id()
	m.MsgHdr.RecursionDesired = true
	m.Question = make([]dns.Question, 1)
	m.Question[0] = dns.Question{os.Args[1], dns.TypeMX, dns.ClassINET}

	err = d.Dial("udp")
	if err != nil {
		fmt.Printf("*** error: %s\n", err.String())
		os.Exit(1)
	}

	in, err := dns.SimpleQuery("udp", d, m)
	if in != nil {
		if in.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 in.Answer {
			fmt.Printf("%v\n", a)
		}
	} else {
		fmt.Printf("*** error: %s\n", err.String())
	}
}