unsigned long netip = inet_addr("192.168.0.1");
unsigned long mask1 = inet_addr("255.255.255.0");
unsigned long mask2 = inet_addr("255.255.255.255");
unsigned long count = ntohl(mask2 - mask1)-1;
char szaddr[16];
struct in_addr in;
unsigned long hostip;
for (unsigned int i = 0; i < count; i++)
{
hostip = ntohl(netip) + i;
in.S_un.S_addr = htonl(hostip);
strcpy(szaddr, inet_ntoa(in));
cout << szaddr << endl;
}
IP地址自动增长。
最新推荐文章于 2022-02-15 09:25:55 发布