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]) } } }
func handleXfrIn(i *dns.Msg) os.Error { q := new(dns.Msg) q.SetAxfr(i.Question[0].Name) m := make(chan *dns.Xfr) fmt.Printf("Preparing Xfr for %s\n", i.Question[0].Name) d := new(dns.Conn) d.RemoteAddr = "127.0.0.1:53" err := d.Dial("tcp") if err != nil { return err } defer d.Close() fmt.Printf("Calling 127.0.0.1 successful\n") go d.XfrRead(q, m) Zone.name = i.Question[0].Name j := 0 for x := range m { Zone.rrs[j] = x.RR j++ } fmt.Printf("Success retrieved %s\n", Zone.name) Zone.size = j return nil }
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()) } }