以编程方式获取主机的 DNS 服务器
我想使用 C++ 获取主机在三种操作系统上使用的 DNS 服务器:OS X、FreeBSD 和 Windows。我想确认以下方法确实是最佳实践,如果不是,则是更好的选择。
- OS X:已经回答了;更新的链接位于 developer.apple.com
- Windows:
GetNetworkParams
- FreeBSD:
/etc/resolv.conf
预先感谢你的帮助!
Using C++, I would like to obtain the DNS servers being used by a host for three operating systems: OS X, FreeBSD, and Windows. I'd like confirmation that the approaches below are indeed best practice, and if not, a superior alternative.
- OS X: already answered; updated link at developer.apple.com
- Windows:
GetNetworkParams
- FreeBSD:
/etc/resolv.conf
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在许多 UNIX 系统(linux、bsd)上,您可以使用解析器函数来获取 DNS 服务器列表: man 3 解析器。
调用
res_init()
后,解析器结构被初始化。解析器结构存储您需要的所有信息。 DNS 服务器列表存储在结构条目nsaddr_list
中。解析器结构的确切规范很可能可以在
resolv.h
中找到。使用解析器函数是获取 DNS 服务器列表的首选方法。
res_init()
很可能会使用/etc/resolv.conf
中找到的信息填充解析器结构。另请参阅resolv.h 的使用
On many unix systems (linux, bsd) you can use the resolver functions to obtain the list of DNS servers: man 3 resolver.
After calling
res_init()
the resolver structure is initialized. The resolver structure stores all the information you need. The list of DNS servers are stored in the struct entrynsaddr_list
.The exact specification of the resolver structure can most likely be found in
resolv.h
.Using the resolver functions is the preferred way to obtain the list of DNS servers.
res_init()
will most likely fill the resolver structure with the information found in/etc/resolv.conf
.Also see Use of resolv.h