69,369
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
void GetIpAddrList(char *pServerName)
{
struct hostent *ipList;
Sleep(100);
ipList = gethostbyname(pServerName);
if(ipList != NULL)
{
while(*ipList->h_addr_list != NULL)
{
struct in_addr tempAddr;
memcpy(&tempAddr,*ipList->h_addr_list,sizeof(struct in_addr));
printf("%s\n",inet_ntoa(tempAddr));
ipList->h_addr_list++;
}
}
}
int main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 )
{
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}
FILE *pData = fopen("data.txt","r+b");
if(pData == NULL)
{
exit(EXIT_FAILURE);
}
char szBuf[BUFSIZ];
while(1)
{
memset(szBuf,0,BUFSIZ);
if(fgets(szBuf,BUFSIZ,pData))
{
if(szBuf[strlen(szBuf)-1] == '\n')
szBuf[strlen(szBuf) -1] = '\0';
printf("%s\n",szBuf);
GetIpAddrList(szBuf);
}
else
break;
}
fclose(pData);
// GetIpAddrList("www.baidu.com");
// GetIpAddrList("www.sina.com.cn");
// GetIpAddrList("www.sohu.com");
getchar();
return 0;
}
while(1)
{
memset(szBuf,0,BUFSIZ);
if(fgets(szBuf,BUFSIZ,pData))
{
int nLen = strlen(szBuf);
if (nLen >= 2 && szBuf[nLen-2] == '\r' && szBuf[nLen-1] == '\n')
szBuf[nLen - 2] = '\0';
else if(nLen >= 1 && szBuf[nLen-1] == '\n')
szBuf[nLen - 1] = '\0';
printf("%s\n",szBuf);
GetIpAddrList(szBuf);
}
else
break;
}