确定哪个名称服务器执行了解析
我在 constr
中设置两个名称服务器,然后使用 res_search
查找 URI 的 IP 地址。
有没有一种简单的方法可以找出两个名称服务器中的哪一个进行了解析? 我知道我可以在 res_search
中设置跟踪并捕获标准输出,但在我的情况下这是不可能的。 名称服务器的地址是否在结果中?
I am setting up two nameservers in constr
and then using res_search
to find the IP address of a URI.
Is there an easy way to find out which of the two nameservers did the resolution? I know that I can set up a trace in res_search
and capture stdout but in my situation that will not be possible. Is the address of the nameserver somewhere in the result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,仅通过查看
res_search()
调用的结果,无法找出哪个名称服务器返回了结果。 该信息仅存在于更高级别的 UDP 数据包标头中,并且在libresolv
解包数据包时不再可用。但是,根据
libresolv
的版本,似乎可以通过使用以下方法向解析器注册“响应钩子”来实现:或
提供给钩子回调的第一个参数将是
发送响应的服务器的 struct sockaddr *
。 下面的代码适用于 MacOS X 10.5.6:顺便说一句,(大多数情况下)可以询问服务器它认为它的名称:
这将返回包含服务器主机名的
TXT
记录(只要DNS 服务器软件中存在此功能且尚未禁用)。这对于识别当前正在为您服务的特定“DNS Anycast Cloud”中的哪台服务器非常有用。
There's no way that I know of to find out which name server returned the result just by looking at the results of a call to
res_search()
. That information is only in the higher-level UDP packet header and is no longer available by the time the packet has been unpacked bylibresolv
.However, depending on the version of
libresolv
it appears to be possible to do it by registering a "response hook" with the resolver using:or
The first parameter supplied to the hook callback will be a
struct sockaddr *
of the server that sent the response. The code below works on MacOS X 10.5.6:BTW it is (mostly) possible to ask a server what it thinks its called:
which will return a
TXT
record containing the server's hostname (so long as the functionality exists in the DNS server software and hasn't been disabled).This can be useful to identify which server out of any particular "DNS Anycast Cloud" is serving you at the moment.
最可靠的方法是进行数据包跟踪。 在开发各种产品的过程中,我还没有看到程序员找到记录此类信息的钩子。
The most reliable way is to do a packet trace. From working on a variety of products, I have not seen programers find hooks for logging that kind of information.