#include "stdafx.h"
#include <stdio.h>
#include <Winsock2.h>
#pragma comment (lib,"ws2_32.lib")
//int _tmain(int argc, _TCHAR* argv[])
int main(int argc, char* argv[])
{
int err = 0;
char szIP[100] = {0};
char strServer[100] = {0};
WORD wVersionRequested = 0;
WSADATA wsaData = {0};
struct hostent* phe = NULL;
if (2 == argc)
{
strcpy(strServer,argv[1]);
}
wVersionRequested = MAKEWORD(1,1); //0x0101
WSAStartup(wVersionRequested,&wsaData);
phe = gethostbyname(strServer);
if (NULL != phe)
{
char ** ppAddr = phe->h_addr_list ;
for (;*ppAddr != NULL ;ppAddr ++)
{
strcpy(szIP,inet_ntoa(*(LPIN_ADDR)*(ppAddr)));
printf("%s\n",szIP);
}
}
WSACleanup();
return 0;
}
gethostbyname获取所有IP(域名解析)
最新推荐文章于 2022-12-08 19:44:09 发布