Linux下域名解析得到ip地址代码如下:
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
struct hostent *p;
int i;
if (argc < 2)
return -1;
p = gethostbyname(argv[1]);
printf("hostname %s\n", p->h_name);
printf("address ");
for (i = 0; p->h_addr_list[i]; i++) {
printf("%s ", inet_ntoa(*(struct in_addr *)p->h_addr_list[i]));
}
printf("\n");
return 0;
}
Linux学习之DNS+DHCP动态域名解析:http://www.linuxdiyf.com/linux/10738.html
shell获取ip地址:http://www.linuxdiyf.com/linux/16671.html
shell脚本获取当前ip地址:http://www.linuxdiyf.com/linux/16109.html
Shell命令读取IP地址:http://www.linuxdiyf.com/linux/803.html
在Linux下获取全国各地IP地址段方法:http://www.linuxdiyf.com/linux/7802.html