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

#include <stdio.h>

#include <netdb.h>//gethostbyname
//#include <cygwin/in.h>//struct in_addr(<linux/in.h>)
#include <netinet/in.h>


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