Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Nightmare Heaven (NH) - NH.c

NH.c

Caricato da:
Scarica il programma completo

  1. /*
  2.         Arcturus Darkstar Enterprises Inc.    1988-2006
  3.         Darkstar WarTech Technologies
  4.         Created bY eddiewrc  <eddiewrc@alice.it>
  5.  
  6.         L'autore +*NON*+ può essere ++IN ALCUN MODO++ ritenuto responsabile
  7.         per eventuali danni o illegalità commesse DAL o CON il suo programma.
  8.         Il software è stato creato ed è distribuito a scopo puramente DIDATTICO.
  9.         Ne è libero l'uso, la modifica e la distribuzione finchè rimane presente
  10.         il nome del programma e il nick dell'autore. Arcturus Darkstar Enterprises...
  11.         ecc. è un nome fittizio che non fa riferimento a *NIENTE*.
  12.  
  13. */
  14. #include <conio.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <winsock.h>
  18. #include <signal.h>
  19. #define WSA_ERROR     0
  20. #define INVALID_SOCK_OPERANDI              10
  21. #define INVALID_SOCK                        9
  22. #define INVALID_IP                          8  
  23. #define INVALID_NUMBERS_OF_SOCKET           7
  24. #define INVALID_NUMBER_OF_STAR_PORT         6
  25. #define INVALID_NUMBER_OF_FINISH_PORT       5
  26. #define CANT_OPEN_LOG                       4
  27.    int SOCK_N;
  28.    WSADATA wsaData;
  29.    SOCKADDR_IN soc;
  30.    char ip[16];
  31.    int s_p, f_p;
  32.    FILE *ofp;
  33.    int i, h, k;
  34.    
  35.    void on_error_exit(int sig);
  36.  
  37.   int main(void)
  38.    {
  39.        signal(SIGINT, on_error_exit);
  40.        
  41.         if (WSAStartup(MAKEWORD(2,2), &wsaData))
  42.            on_error_exit(WSA_ERROR);
  43.         printf("\nArcturus Darkstar Enterprises Inc. 1988-2006");
  44.         printf("\nAD ASTRA! :: NightMare Heaven");
  45.         printf("\nInput IP of target host: ");
  46.         if (!scanf("%s", ip))
  47.             on_error_exit(INVALID_IP);
  48.         printf("\nInput the number of socket: ");
  49.         if (!scanf("%d", &SOCK_N))
  50.             on_error_exit(INVALID_NUMBERS_OF_SOCKET);
  51.         SOCKET s[SOCK_N];
  52.         int r[SOCK_N];
  53.         printf("\nStart at port: ");
  54.         if (!scanf("%d", &s_p))
  55.             on_error_exit(INVALID_NUMBER_OF_STAR_PORT);
  56.         printf("\nFinish at port: ");
  57.         if (!scanf("%d", &f_p))
  58.             on_error_exit(INVALID_NUMBER_OF_STAR_PORT);
  59.         if (!(ofp = fopen("log.txt", "w")))
  60.             on_error_exit(CANT_OPEN_LOG);
  61.         for (i = 0; i < SOCK_N; i++)
  62.               if( !(s[i] = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) )  
  63.                       on_error_exit(INVALID_SOCK);
  64.                  
  65.                    soc.sin_family = AF_INET;
  66.                    soc.sin_addr.s_addr = inet_addr(ip);
  67.          
  68.          fprintf(ofp, "\n%s\n%s\n%s\n%s\n\n",
  69.                       "Arcturus Darkstar Enterprises Inc.    1988-2006",
  70.                       "Darkstar WarTech Technologies",
  71.                       "AD ASTRA! - Nightmare Heaven",
  72.                       "Created bY eddiewrc");
  73.                              
  74.         for (i = s_p; i < f_p; )
  75.              {
  76.                h = i;
  77.                printf("\nConnection");
  78.                fprintf(ofp, "\nConnection");
  79.                for (k = 0; k < SOCK_N; k++)
  80.                     {
  81.                       printf("\nOpening the %d socket", k);
  82.                       soc.sin_port = htons(i++);
  83.                       r[k] = connect( s[k], (SOCKADDR*) &soc, sizeof(soc) );
  84.                     }
  85.                    
  86.               //  _sleep(2);  
  87.                     printf("\nChecking..");
  88.                     fprintf(ofp, "\nChecking..");
  89.                for (k = 0; k < SOCK_N; k++)
  90.                     {
  91.                       if (r[k] == SOCKET_ERROR)
  92.                          {
  93.                             printf("\nProcessing Port %d; Status = CLOSE", (h + k));
  94.                             fprintf(ofp, "\nProcessing Port %d; Status = CLOSE", (h + k));
  95.                          }
  96.                       else
  97.                          {
  98.                             printf("\nProcessing Port %d; Status = OPEN", (h + k));
  99.                             fprintf(ofp, "\nProcessing Port %d; Status = OPEN", (h + k));
  100.                             closesocket(s[k]);
  101.                                  if( !(s[k] = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) )  
  102.                                        on_error_exit(INVALID_SOCK_OPERANDI);
  103.                          }
  104.                     }  
  105.              }
  106.      getch();
  107.      printf("\nFatto.");
  108.      return 0;
  109.    }
  110.    
  111.    void on_error_exit(int sig)
  112.     {
  113.       if (sig == WSA_ERROR)
  114.           printf("\nWSA ERROR");
  115.       else if (sig == INVALID_SOCK_OPERANDI)
  116.           printf("\nSocket Lost");
  117.       else if (sig == INVALID_SOCK)
  118.           printf("\nInvalid Socket");
  119.       else if (sig == INVALID_NUMBERS_OF_SOCKET)
  120.            printf("\nInvalid Numbers of Socket");
  121.       else if (sig == INVALID_NUMBER_OF_STAR_PORT)
  122.            printf("\nInvalid Number of start port");
  123.       else if (sig == INVALID_NUMBER_OF_FINISH_PORT)
  124.            printf("\nInvalid number of finish port");
  125.       else if (sig == CANT_OPEN_LOG)
  126.            {
  127.                printf("\nCan't open the log file");
  128.                printf("\nWould you (E)xit or (C)ontinue?");
  129.                  if((getch()) == 'e' )
  130.                     exit(0);
  131.                  else
  132.                     return;
  133.            }    
  134.       else if (sig == SIGINT)
  135.           {
  136.              printf("\nScanning stopped. \nWould you (E)xit or (C)ontinue?");
  137.              if((getch()) == 'e' )
  138.                 exit(0);
  139.              else
  140.                 return;
  141.           }    
  142.       getch();
  143.       exit(1);
  144.       return;
  145.     }