首 页文章中心

Linux学习网

您的位置Linux学习网 > Linux企业应用 > 文章内容

linux环境下用gethostbyname函数获取 DNS的服务器列表 名称 IP

作者:佚名  来源:不详  发布时间:2007-6-9 8:29:00
#include

#include //gethostbyname
//#include //struct in_addr()
#include


void getHostName()
{
struct hostent *myhost;
char ** pp;
struct in_addr addr;
myhost = gethostbyname("www.linuxdiyf.com");

printf("host name is %s\n",myhost->h_name);
// pp = myhost->h_aliases;
// while(*pp!=NULL)
// {
// printf("%s\n",*pp);
// pp++;
// }
for (pp = myhost->h_aliases;*pp!=NULL;pp++)
printf("%02X is %s\n",*pp,*pp);
pp = myhost->h_addr_list;
while(*pp!=NULL)
{
addr.s_addr = *((unsigned int *)*pp);
printf("address is %s\n",inet_ntoa(addr));
pp++;
}
}

结果:

host name is cachesh1.a.linuxdiyf.com
6B1508 is www.linuxdiyf.com
6B1518 is d7.a.linuxdiyf.com
address is 61.152.234.72
address is 61.152.234.73
address is 61.152.234.75
address is 61.152.234.76
address is 61.152.234.77
address is 61.152.234.71
收藏本页到: 365Key | del.icio.us | | 添加到雅虎收藏+
  • 网站帮助 - 广告合作 - 网站地图