简体   繁体   English

如何使用固定的DNS服务器获取主机名的IP?

[英]How can I get the IP of a hostname using a fixed DNS server?

Is there an easy way, on *nix platforms(Linux specifically) to get the IP address of a hostname, while supplying a custom DNS server to use in place of the system's configured one? 在* nix平台(特别是Linux)上,是否有一种简单的方法来获取主机名的IP地址,同时提供自定义DNS服务器以代替系统已配置的DNS服务器? I want to access this information from a C program. 我想从C程序访问此信息。

You will need to use your own resolver, directly sending DNS packets, instead of relying on the system's resolver and gethostbyname . 您将需要使用自己的解析程序,直接发送DNS数据包,而不是依赖系统的解析程序和gethostbyname You would probably want to use a library, such as adns . 您可能要使用诸如adns之类的库。

nslookup <hostname> <dns server>

例如:

nslookup www.example.com ns1.example.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM