package ksyunwarning import ( "context" "fmt" "net" "time" ) // LookupDomainNameIp 使用net包做DNS解析请求 func LookupDomainNameIp(domainString, nameServer string) (dst []string) { r := &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { d := net.Dialer{ Timeout: 3 * time.Second, } return d.DialContext(ctx, "udp", fmt.Sprintf("%s:53", nameServer)) }, } var err error dst, err = r.LookupHost(context.Background(), domainString) if err != nil { s.fileLogger.Error("LookupDomainNameIp LookupHost Err : %v", err) } return }
参考:http://www.linvon.cn/posts/golang-%E6%8C%87%E5%AE%9A-dns-%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%81%9A%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90/
标签:string,err,E5%,E6%,DNS,Go,net,解析 From: https://www.cnblogs.com/zhangmingda/p/17680762.html