代码如下所示,vc6.0上运行通过
#include
#include
#pragma comment(lib,"Wsock32.lib")
int main()
{
unsigned long ulBeginIP;
unsigned long ulEndIP;
char szBeginIP[20] = "110.110.255.0";
char szEndIP[20] = "110.110.255.255";
unsigned long ulCurIP;
unsigned short ausPort[10] = {80,8080};
int PortNum = 2;
int i;
in_addr inaddr;
FILE *pFile = NULL;
pFile = fopen("ip.txt", "at");
if (NULL == pFile)
{
printf("open ip.txt fail.\r\n");
return 0;
}
ulBeginIP = ntohl(inet_addr(szBeginIP));
ulEndIP = ntohl(inet_addr(szEndIP));
for (ulCurIP = ulBeginIP; ulCurIP <= ulEndIP; ulCurIP++)
{
for (i = 0; i < PortNum; i++)
{
inaddr.S_un.S_addr = htonl(ulCurIP);
fprintf(pFile, "%s:%d\r\n", inet_ntoa(inaddr), ausPort[i]);
}
}
fclose(pFile);
return 1;
}
诶有!真是笨蛋!好好学C++语言吧!