Made an example in godoc for it

This commit is contained in:
Miek Gieben 2012-09-02 09:02:33 +02:00
parent 9a5ffa1038
commit 29d6e9f9a6
2 changed files with 1 additions and 40 deletions

View File

@ -1,6 +1,5 @@
.PHONY: ex
EXAMPLES=mx \
chaos \
EXAMPLES=chaos \
key2ds \
axfr \
reflect \

View File

@ -1,38 +0,0 @@
package main
// Print the MX records of a domain
// (c) Miek Gieben - 2011
import (
"fmt"
"github.com/miekg/dns"
"os"
)
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 := new(dns.Client)
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)
}
}