如何获取getaddrinfo查询的DNS服务器地址

发布于 2024-08-12 20:53:17 字数 101 浏览 0 评论 0原文

我是 C 语言 BSD 套接字编程的新手。我可以使用“getaddrinfo”函数查询网址以获取其关联的 IP 地址。但我想知道 getaddrinfo 从哪个 dns 服务器查询此信息。

I'm newbie to BSD socket programming in C. I can query a web address to get its associated ip addresses with "getaddrinfo" function. But i want to know which dns server getaddrinfo queries this information from.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

地狱即天堂 2024-08-19 20:53:17

如果您使用的是 linux 或 UNIX 平台,请尝试查看 man -k resolver 并查找 resolver 手册页或类似 res_init 的函数页面代码>、<代码>res_search等。等人。这些是 DNS 的 unix API,看起来虽然没有直接的方法来完成您想做的事情,但可以通过函数及其返回内容的组合来收集信息,并进行其他一些数据处理。

至于wireshark知道发生了什么,它并不真正知道。它只是监视来回流动的数据包并打印出它所看到的内容。解析器是知道的,这就是我建议的 API。

If you are on linux or a unix platform, try looking at man -k resolver and look for the resolver man page or a page for functions like res_init, res_search, et. al. Those are the unix APIs to DNS, and it looks like, while there's no direct way to do what you want to do, one could glean the information through a combination of the functions and what they return, and doing a few other massaging of data.

With regard to wireshark knowing what's going on, it doesn't really know. It's just monitoring packets as they flow to and fro and printing out what it sees. The resolver is what knows, and that's the API I suggested.

跨年 2024-08-19 20:53:17

我认为您无法找出它使用了哪个,但它使用了 /etc/resolv.conf 中的一个

I don't think you can find out which it used, but it uses one from /etc/resolv.conf

烟酉 2024-08-19 20:53:17

如果您使用的是 Linux,您可以查看源代码来“挖掘”。基于它打印出服务器地址的能力,我认为除了解析 /etc/resolv.conf 之外,还必须有一些方法来做到这一点。

在 Windows 上,有一个非常复杂的 API 用于此目的。

If you are on Linux, you can look at the source to 'dig'. Based on it's ability to print out the server address, I think there must be some means to do this other than just parsing the /etc/resolv.conf.

On Windows, there is a very convoluted API for the purpose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文