Skip to content

Instantly share code, notes, and snippets.

@003random
Created November 23, 2019 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 003random/cfa967b91a052b73145568222ef74433 to your computer and use it in GitHub Desktop.
Save 003random/cfa967b91a052b73145568222ef74433 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/miekg/dns"
"net"
"os"
"log"
"fmt"
)
func main() {
config, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
log.Fatal(err)
}
c := new(dns.Client)
m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeMX)
m.RecursionDesired = true
r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Port))
if r == nil {
log.Fatalf("*** error: %s\n", err.Error())
}
fmt.Println(dns.RcodeToString[r.Rcode])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment