Made an example in godoc for it
This commit is contained in:
parent
9a5ffa1038
commit
29d6e9f9a6
|
@ -1,6 +1,5 @@
|
||||||
.PHONY: ex
|
.PHONY: ex
|
||||||
EXAMPLES=mx \
|
EXAMPLES=chaos \
|
||||||
chaos \
|
|
||||||
key2ds \
|
key2ds \
|
||||||
axfr \
|
axfr \
|
||||||
reflect \
|
reflect \
|
||||||
|
|
38
ex/mx/mx.go
38
ex/mx/mx.go
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue