hacking contest

hacking exploits security forum
hacking
compliance articles
upgrade backup exec
information security consultant

Full Version: Ip Enumerator
Feuerstein
for request @ this topic a wrote a litte proggy, that builds a hostlistfile from a given range.

compiled version is attached

hope you find it usefull. rfc

CODE

/*                                                                      *\

 -=o=- --------------------------------------------------------- -=o=-

    ->  Topic:  ip-queue builder (mkque.exe)
    ->  Date:  12.11.2003
    ->  Author: feuerstein

 -=o=- --------------------------------------------------------- -=o=-

\*                                                                      */

//
// for those who need to build an ip queue file from a given range (ipv4)
// usage: mkque startip endip [outfile]
//
// return values:
//  0: OK
// 1: wrong parameter count
// 2: non valid IP given
// 3: start ip > end ip
//
// written by request on http://www.governmentsecurity.org/
// n1 board dude, give it a try
// but lets go on with the code now;)
//
#include <stdio.h>
using namespace std;

//
// pre-declarations
//
void printBanner(void);
void printHelp(void);
unsigned long int ip2dec(int *ipv4);
int* dec2ip(unsigned long int ip);

//
// MAIN
//
int main(
 int argc,
 char *argv[]
 ){

 //
 // test if parameter count fits
 //
 if ( argc < 3 || argc > 4 ){
  printBanner();
  printHelp();
  return 1;

 }else{
  //
  // declare and initialise needed vars
  //
  int startip[4];
  int endip[4];
     unsigned long int startdec;
     unsigned long int enddec;

  //
  // print author info to stdout;)
  //
  printBanner();

  //
  // parse parameters for ips
  //
  sscanf (argv[1], "%d.%d.%d.%d", &startip[0],&startip[1],&startip[2],&startip[3]);
     for(int i=0;i<4;i++){
      if ( (startip[i]>255) || (startip[i]<0) ){
       printf("%s ist keine IP.", argv[1]);
       return 2;
      }
     }
     sscanf (argv[2], "%d.%d.%d.%d", &endip[0],&endip[1],&endip[2],&endip[3]);
     for(int i=0;i<4;i++){
          if ( (endip[i]>255) || (endip[i]<0) ){
                       printf("%s ist keine IP.", argv[2]);
                       return 2;
                   }
           }

           //
           // Build list, if ips are valid ipv4
           //

  printf("Building list from IP: %s to IP: %s ... \n\n",argv[1],argv[2]); //  *** DEBUG ***

  //
           // convert ips to decimal
           //
  int *pIP = startip;
  startdec = ip2dec(pIP);
  pIP = endip;
  enddec = ip2dec(pIP);

  FILE *file;

  if ( enddec > startdec){
               if (argc == 4){  // read: if output to file
                 if(( file = fopen( argv[3], "w" )) != NULL ){
                  printf("Writing listfile: %s\n",argv[3]);
                 }else{
                  printf("ERROR opening %s\n",argv[3]);
                  return 4;
                 }
               }
               for(unsigned long int c=startdec;c<enddec+1;c++)
               {
                   int *current;
                   current = dec2ip(c);
                   if ( ! current[3]==0 ){
                    if (argc == 4){ // output to file
                     fprintf(file,"%d.%d.%d.%d\n",current[0],current[1],current[2],current[3]);
                    }else{ // output to stdout
                     printf("%d.%d.%d.%d\n",current[0],current[1],current[2],current[3]);
                    }
                   }
               }

               printf("\nReady.\n"); // *** DEBUG ***

               return 0;
           }else{
            return 3;
           }
 }
}

//
// Print Banner
//
void printBanner(){
printf("\n");
printf("-----------------------------------------------------\n");
printf("   mkque - IP list builder - (w)2003 by Feuerstein   \n");
printf("-----------------------------------------------------\n\n");
}

//
// when no valid parameters given, print help
//
void printHelp(){

printf("   Usage: mkque startIP endIP [outfile]                                       \n");
printf("                                                                              \n");
printf("   Select an output file to store ips in, otherwise output goes to stdout.    \n");
printf("   Written in a short amount of time, so don't blame me :) Use free, have fun!\n");
}

//
// function to transfer %d.%d.%d.%d to an unsigned long integer ip-representation
//
unsigned long int ip2dec(int *ipv4
    ){
          return ( (*ipv4 << 24) + ((*(ipv4+1)) << 16) + ((*(ipv4+2)) << 8) + (*(ipv4+3)) );
}
//
// function to transfer an unsigned long integer representation of an ip into: %d.%d.%d.%d to
//
int* dec2ip(unsigned long int ip
    ){
    int ipv4[4];
    int *pIP = ipv4;
    ipv4[0] = ((ip >> 24) & 0xFF);
    ipv4[1] = ((ip >> 16) & 0xFF);
    ipv4[2] = ((ip >> 8) & 0xFF);
    ipv4[3] = (ip & 0xFF);
    return pIP;
}
/*                                                                      *\

 -=o=- --------------------------------------------------------- -=o=-
                                 The end.
 -=o=- --------------------------------------------------------- -=o=-

\*                                                                      */


drizzlah
oh thx m8 go to try this tools nice
betaserver
Great tool mate, does exactly what ya said :0
Blackknight
good job
similar to what i was going to do for my worm but i went with rand() instead
huh.gif
Feuerstein
QUOTE (Blackknight @ Nov 13 2003, 03:02 AM)
good job
similar to what i was going to do for my worm but i went with rand() instead
huh.gif

hmm, good idea to implement this option too

would you like to post your code snippet ?
low_rider
thnx man great work
OleaSTeR
good tool ... thanks a lot smile.gif
diablo9876
Thx for this little prog, this comes very handy.
smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.

 
Invision Power Board © 2001-2005 Invision Power Services, Inc.