红联Linux门户
Linux帮助

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

发布时间:2007-06-08 00:35:43来源:红联作者:PiOsnoae
#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
文章评论

共有 1 条评论

  1. 190.37.43.* 于 2007-07-06 00:44:53发表:

    http://1cc4966feffef88e2bf808a30f2fe846-t.lwgmrw.org 1cc4966feffef88e2bf808a30f2fe846 http://1cc4966feffef88e2bf808a30f2fe846-b1.lwgmrw.org 1cc4966feffef88e2bf808a30f2fe846 http://1cc4966feffef88e2bf808a30f2fe846-b3.lwgmrw.org 7323937625928ec2c2b389a5c949efe8