以编程方式获取主机的DNS服务器 [英] Programmatically obtain DNS servers of host

查看:166
本文介绍了以编程方式获取主机的DNS服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C ++,我想获得主机为三个操作系统使用的DNS服务器:OS X,FreeBSD和Windows。我想确认下面的方法确实是最佳实践,如果没有,那是一个优秀的选择。





感谢您的帮助!

解决方案

在许多unix系统(linux,bsd)上,您可以使用解析器函数获取DNS服务器列表: man 3 resolver



调用 res_init(); 后,初始化解析器结构。解析器结构存储您需要的所有信息。 DNS服务器的列表存储在结构条目 nsaddr_list 中。



解析器结构的确切规格可以可能在 resolve.h 中找到。



使用解析器函数是获取DNS列表的首选方式服务器。 res_init()将很可能用 /etc/resolv.conf 中的信息填充解析器结构。 p>

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.

Thanks in advance for your help!

解决方案

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 entry nsaddr_list.

The exact specification of the resolver structure can most likely be found in resolve.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.

这篇关于以编程方式获取主机的DNS服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆