linux c 编程之二 列出ip段.

linux c 编程之二 列出ip段.

一思路:


有些扫描器,可能需要提供ip列表的.这个可以通过一些扫描器,得到的结果来 作为ip文件的输入,现在自己来写程序提供这些ip.产生a b c 类的ip.

 

二函数说明.


其中用到的选择函数switch .循环函数for
查相关函数说明.这里不提供说明! 


三编写程序:

 

建立文件:
nightcat@nightcat$vi showip.c


编辑以下内容:

/*showip.c version 1.0

 * the tools show ip include a b and c class's ip

 * you can see the tips for entering .

 * the tools writen by nightcat  email:ncnynl@hotmail.com

 *
 *Code BY Nightcat

 *April 2003

 * */

#include<stdio.h>

main()

{

  int chioce,i,j,k,a,b,c;

  FILE * fp;

 

 printf("please enter your chioce,/n enter 1 chioce a class./n enter 2 chiose b class. /n enter 3 chiose c class:/n");

  scanf("%d",&chioce);

  switch (chioce)
  {

      
 case 1:
                 
 printf("enter a as 211 enter /' -1/' to end  /n");
                     scanf("%d",&a);
                 
 if(a==-1){

                  break;

                  }
                
 if((fp=fopen("listipa.txt","w+"))==NULL){
                           printf("cann't open files./n");
                       
  exit(1);
                
 }
                 
 for(i=1;i<=254;i++){
                         
  for(j=1;j<=255;j++){
                                        for(k=1;k<=255;k++)
                                 fprintf(fp,"%d.%d.%d.%d/n",a,i,j,k);
                             }
                 
  }
                 
 fclose(fp);
                 
 break;
 
      
 case 2:
                 
  printf("enter b as 211.239 enter /'-1/' to end/n");
                    scanf("%d.%d",&a,&b);
                 
  if(a==-1){
                 
   break;
                 
  }
                 
 if((fp=fopen("listipb.txt","w+"))==NULL){
                     
  printf("cann't open files /n");
                     
     exit(1);
                  }
                 
 for(i=1;i<=255;i++){
                         
  for(j=1;j<=255;j++){
                                       fprintf(fp,"%d.%d.%d%.d/n",a,b,i,j);
                              }
                 
 }
                 
 fclose(fp);
                 
 break;

     
 
 case 3:
                 
  printf("enter c as 211.239.151 enter /'-1/' to end /n");
                    scanf("%d.%d.%d",&a,&b,&c);
                 
  if(a==-1){
                 
   break;
                 
   }
                 
  if((fp=fopen("listipc.txt","w+"))==NULL){
                         printf("cann't open files/n");
                     
   exit(1);
                 
   }
                 
  for(i=1;i<=255;i++){
                            fprintf(fp,"%d.%d.%d.%d/n",a,b,c,i);
                 
  }
                 
  fclose(fp);
                 
  break;
 
 }

}


保存退出:

:wq

编译执行:
nightcat@nightcat$gcc -o showip showip.c
nightcat@nightcat$./show

 

四.后言:

这个程序十分简单的.主要就是用了选择函数switch,和循环函数for.


还有文件的读写函数.fopen ,fprintf.fclose.

 


五.联系我:

nickname:nightcat

e-mail:ncnynl@hotmail.com

qq:1043931

icq:153436005

阅读更多
个人分类: 原创文章
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭