Skip to content

Instantly share code, notes, and snippets.

@oinume
Created June 4, 2015 10:27
Show Gist options
  • Save oinume/c4a7589c7cf883d128c6 to your computer and use it in GitHub Desktop.
Save oinume/c4a7589c7cf883d128c6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"github.com/miekg/dns"
"strings"
)
func main() {
client := &dns.Client{}
message := &dns.Msg{}
message.SetQuestion(os.Args[1] + ".", dns.TypeCNAME)
message.RecursionDesired = true
config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
r, _, err := client.Exchange(message, config.Servers[0]+":"+config.Port)
if err != nil {
panic(err)
}
if r.Rcode != dns.RcodeSuccess {
panic(r.Rcode)
}
for _, a := range r.Answer {
if cname, ok := a.(*dns.CNAME); ok {
fmt.Printf("%s\n", cname.String())
if strings.Contains(cname.String(), "custom-domain.amebaowndme.com") {
fmt.Println("OK!")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment