home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Porting / unix / domscan.c < prev    next >
C/C++ Source or Header  |  1999-11-04  |  3KB  |  110 lines

  1. /**********************************
  2.  * Domain Scanner v2.0            *
  3.  * by HoGs HeaD                   *
  4.  * Fixed up the screwy stuff.     *
  5.  * (C)1998 HoGs HeaD              *
  6.  * You may not modify and         *
  7.  * then redistribute              *
  8.  * this source.                   *
  9.  *********************************/
  10.  
  11. #include <stdio.h>
  12. #include <sys/socket.h>
  13. #include <sys/types.h>
  14. #include <sys/wait.h>
  15. #include <netinet/in.h>
  16. #include <errno.h>
  17. #include <netdb.h>
  18. #include <signal.h>
  19.  
  20. void brk(int no){
  21.    printf("^C Interrupt!\n");
  22.    exit(1);
  23. }
  24.  
  25. void main(int argc, char **argv)
  26. {
  27.     struct hostent *host;                       /* init stuff */
  28.     struct sockaddr_in sa;
  29.     int net, error;
  30.     int port=23, i, done=0;
  31.     char *curr_ip, *del, *cm[100];
  32.     int A1, A2, A3, A4;
  33.     int B1, B2, B3, B4;
  34.     int C1, C2, C3, C4;
  35.    printf("\nDomain Scanner v2.0 by HoGs HeaD\nHit any key to end.\n");
  36.    if(argc < 3){
  37.         printf("Usage: domscan ip_begin ip_end port\nwhere ip_start equals the
  38. beginning IP(ie 127.26.26.1)\nand ip_end equals the ending IP(ie 147.26.27.12)\
  39. nand port is the port to check on\n\n");
  40.         exit(0);
  41.    }
  42.  
  43.    signal(SIGINT, brk);
  44.       if(argv[3]==NULL){
  45.    }else{
  46.       port=atoi(argv[3]);
  47.    }
  48.  
  49.    /* Parse in the first Ip.... */
  50.  
  51.    curr_ip=argv[1];
  52.    del=(char *)strtok(curr_ip, ".");
  53.    A1=atoi(del);
  54.    del=(char *)strtok(NULL, ".");
  55.    A2=atoi(del);
  56.    del=(char *)strtok(NULL, ".");
  57.    A3=atoi(del);
  58.    del=(char *)strtok(NULL, ".");
  59.    A4=atoi(del);
  60.  
  61.    /* Read in Second Ip... */
  62.    curr_ip = argv[2];
  63.    del=(char *)strtok(curr_ip, ".");
  64.    B1=atoi(del);
  65.    del=(char *)strtok(NULL, ".");
  66.    B2=atoi(del);
  67.    del=(char *)strtok(NULL, ".");
  68.    B3=atoi(del);
  69.    del=(char *)strtok(NULL, ".");
  70.    B4=atoi(del);
  71.    /* We're finished parsing, now onto the actual scan... */
  72.    C1=A1;
  73.    C2=A2; /* SaVe DeM VaLueS! */
  74.    C3=A3;
  75.    C4=A4;
  76. for(A4=C4;A4<=B4; A4++){
  77. for(A3=C3;A3<=B3; A3++){
  78. for(A2=C2;A2<=C2; A2++){
  79. for(A1=C1;A1<=B1; A1++){
  80.    sprintf(curr_ip, "%d.%d.%d.%d", A1, A2, A3, A4);               /* build the
  81. ip */
  82.    if( ( fork() ) == 0){                                          /* fork a chi
  83. ld */
  84.    sa.sin_family = AF_INET;
  85.    sa.sin_addr.s_addr = inet_addr(curr_ip);
  86.    sa.sin_port = htons(port);                                     /* socket is
  87. set and... */
  88.    net = socket(AF_INET, SOCK_STREAM, 0);                         /* create socket */
  89.    if(net < 2){ 
  90.       exit(2);     
  91.    }
  92.    alarm(5);                                                      /* wait 5 sec
  93. onds until we cancel connection */
  94.    error = connect(net, (struct sockaddr *)&sa, sizeof sa);       /* attempt co
  95. nnection */
  96.    
  97.    error < 0 ? printf("Error connecting to: %s %s\n", curr_ip, strerror(errno)) : printf("Connection success at: %s\n", curr_ip);
  98.    shutdown(net, 2);                                                /* disconne
  99. ct socket */
  100.    exit(0);                                                         /* exit chi
  101. ld process */
  102.    }
  103.    
  104.  }
  105. }
  106. }
  107. }
  108. gets((char *)i);          /* Wait for enter to be pressed to exit */
  109. }
  110.