C语言Win/Linux IP地址段整理
说明:只写了C段D段例:172.16.0.0 172.16.255.255
编译:gcc ip.c -o ip
#include <stdio.h> int main() { int i,ii,iii,i1,i2,ch; int n=0; char w3[36]; FILE *fp; FILE *fp1; //检测行数 fp=fopen("ip.txt","r"); while((ch = fgetc(fp)) != EOF) {if(ch == '\n'){n++;}} fclose(fp); //逐行读取 fp=fopen("ip.txt","r+"); for(i=1;i<=n;i++){ fgets(w3,100,fp); int da0,da1,da2,da3,da4,da5,da6,da7; sscanf(w3,"%d.%d.%d.%d %d.%d.%d.%d",&da0,&da1,&da2,&da3,&da4,&da5,&da6,&da7); for(i2 = da0; i2 <= da4; i2++){ for(i1 = da1; i1 <= da5; i1++){ for(ii = da2; ii <= da6; ii++){ if (ii==da2){ for(iii = da3; iii <= 255; iii++) { printf("%d.%d.%d.%d\n",i2,i1,ii,iii); } ii++; } if(ii<da6){ //ii++; for(iii = 0; iii <= 255; iii++) { printf("%d.%d.%d.%d\n",i2,i1,ii,iii); } } else { for(iii = 0; iii <= da7; iii++) { fp1=fopen("ips.txt","a+"); fprintf(fp1,"%d.%d.%d.%d\n",i2,i1,ii,iii); fclose(fp1); } } }}} //for结束 } fclose(fp); return 0; }
CM部落 》原创,转载请保留文章出处。
本文链接:C语言Win/Linux IP地址段整理 https://www.itkz.cn/note/93.html
版权声明:若无特殊注明,本文皆为《
正文到此结束
发表吐槽
你肿么看?
既然没有吐槽,那就赶紧抢沙发吧!