-
通过域名显示IP列表
#define __LINUX__
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
#include <stdio.h>
#ifdef __LINUX__
#include <netdb.h>
#include <sys/socket.h>
#else
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#endif
int main(int argc, char* argv[])
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
struct hostent* hptr;
char** pptr;
char hostname[32];
char str[32];
#ifndef __LINUX__
WSADATA wsa;
WSAStartup(MAKEWORD(2,2), &wsa);
#endif
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if(gethostname(hostname,sizeof(hostname)))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
#ifdef __LINUX__
printf("gethostname calling error: %d \n");
#else
printf("gethostname calling error: %d \n", WSAGetLastError());
#endif
return 1;
}
printf("localhost name: %s\n", hostname);
strcpy(hostname, argv[1]);
if((hptr = gethostbyname(hostname)) == NULL)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
printf("gethostbyname calling error\n");
return 1;
}
int i = 0;
pptr = hptr->h_addr_list;
for(;*pptr != NULL; pptr++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
#ifdef __LINUX__
printf("address: %s \n", inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str)));
#else
printf("address: %s \n", inet_ntoa(*( (struct in_addr *)hptr->h_addr_list[i] )));
i++;
#endif
}
return 0;
}
-
相关阅读:
在一组降序排列的数组中插入一个数据,插入后,数组中数据依然按降序排列
轮播图无限滚动
微软雅黑的Unicode码和英文名
javascript中的this
javascript构造函数及原型对象
object.prototype.call
Array.prototype.forEach数组遍历
键盘event.which属性
Object.prototype.toString()
parseInt()解析整数与parsetFloat()解析浮点数
-
原文地址:https://www.cnblogs.com/frischzenger/p/1584672.html
Copyright © 2020-2023
润新知