有没有办法指定使用哪个DNS服务器进行名称查找?
看一下https://golang.org/pkg/net/#LookupHost,它似乎只会使用本地解析器
LookupHost looks up the given host using the local resolver. It returns a slice
of that host's addresses.同样在前面的链接中
It can use a pure Go resolver that sends DNS requests directly to
the servers listed in /etc/resolv.conf,如何对任意服务器进行查找,就像使用dig一样?
dig @8.8.8.8 google.com发布于 2020-01-24 11:01:05
如果我读对了那个文档(也许不是)...
创建自己的本地解析程序,使用自定义拨号程序,使用您要使用的域名系统地址(https://golang.org/pkg/net/#Resolver),然后使用该解析程序的LookupAddr函数?
编辑:
package main
import (
"context"
"net"
"time"
)
func main() {
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}
return d.DialContext(ctx, network, "8.8.8.8:53")
},
}
ip, _ := r.LookupHost(context.Background(), "www.google.com")
print(ip[0])
}这似乎起作用了-在我的防火墙上,这显示我的机器正在打开与Google的连接,而不是本地域控制器
https://stackoverflow.com/questions/59889882
复制相似问题