Programmatically obtain DNS servers of host

前端 未结 1 1532
余生分开走
余生分开走 2020-12-16 18:09

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 be

相关标签:
1条回答
  • 2020-12-16 18:42

    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 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

    0 讨论(0)
提交回复
热议问题