package main import ( "fmt" "net" ) func main() { //查找DNS A记录 iprecords, _:=net.LookupIP("landv.cn") for _,ip:=range iprecords{ fmt.Println(ip) } //查找DNS CNAME记录 canme, _:=net.LookupCNAME("www.baidu.com") fmt.Println(canme) //查找DNS PTR记录 ptr,e :=net.LookupAddr("8.8.8.8") if e != nil { fmt.Println(e) } for _, ptrval:=range ptr{ fmt.Println(ptrval) } //查找DNS NS记录 nameserver,_:=net.LookupNS("baidu.com") for _,ns :=range nameserver{ fmt.Println("ns记录",ns) } //查找DNS MX记录 mxrecods,_ :=net.LookupMX("google.com") for _,mx :=range mxrecods{ fmt.Println("mx:",mx) } //查找DNS TXT记录 txtrecords, _ := net.LookupTXT("baidu.com") for _, txt := range txtrecords { fmt.Println("txt:",txt) } }
运行结果
185.199.111.153 185.199.108.153 185.199.109.153 185.199.110.153 www.a.shifen.com. dns.google. ns记录 &{dns.baidu.com.} ns记录 &{ns7.baidu.com.} ns记录 &{ns2.baidu.com.} ns记录 &{ns3.baidu.com.} ns记录 &{ns4.baidu.com.} mx: &{aspmx.l.google.com. 10} mx: &{alt1.aspmx.l.google.com. 20} mx: &{alt2.aspmx.l.google.com. 30} mx: &{alt3.aspmx.l.google.com. 40} mx: &{alt4.aspmx.l.google.com. 50} txt: v=spf1 include:spf1.baidu.com include:spf2.baidu.com include:spf3.baidu.com a mx ptr -all txt: google-site-verification=GHb98-6msqyx_qqjGl5eRatD3QTHyVB6-xQ3gJB5UwM