求编程达人帮我编个小程序~

2024-11-07 10:42:32
推荐回答(2个)
回答1:

代码如下所示,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;
}

回答2:

诶有!真是笨蛋!好好学C++语言吧!