/*
  This is just a little proggie to scan the www server for their
  server type and version.
  
  I cannot and will not be held responsible nor legally bound for the
  malicious activities of individuals who come into possession of this
 
  [03.10.99] - v1.02 some lame segmentation faults fixed :\
  [20.09.99] - v1.01 added the option for mass scan 
   
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>

#define ERROR -1
#define MAXDATASIZE 300
#define MESSAGE "HEAD / HTTP/1.0\n\n"
#define DATE "[03.10.99]"

/* Function prototypes */
char *GetHTTP(int s,char *,int port);

/* Global Vars */

char buf[MAXDATASIZE];
char message[] = MESSAGE;


void main(int argc,char *argv[])
{
  /*** SOCKET VARIABLES ***/
  int s;
  /*** TARGET VARIABLES ***/
  FILE *in;
  char buffer[50],result[50];
  int i=0,port=80;
      
  
  
  if ((argc >=5) || (argc<=1))
    {
      printf("\nHttpScan v1.02\n");
      printf("\nCoded By SkeMet");
      printf("\n%s",DATE);
      printf("\n\nusage: %s ip\n       %s -f ipfile\n\n",argv[0],argv[0]);
      exit(0);
    };
    
  
  port=atoi(argv[2]); 
  
  if (argc==4)
    {
      if ((in=fopen(argv[2], "r+"))==NULL)
        {
          printf("Error: Unable to open IP file\n");
          exit(1);
        };
                 
      while (!feof(in))
       {
          fscanf(in,"%s",buffer);
          
          if ((s=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
            {
              printf("ERROR: socket() failed\n");
              exit(0);
            };
          printf("\nServer: %s\n",buffer);        
          printf("%s",GetHTTP(s,buffer,port));
        
       };   
    }      
else
  {
    if ((s=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
      {
        printf("ERROR: socket() failed\n");
        exit(0);
      };
    
    printf("SERVER: %s\n",argv[1]);
    printf("%s",GetHTTP(s,argv[1]));
  }

  printf("\nCoded by Skemet, U might fool many people but U can't fool your self!\n\n");
};

char *GetHTTP(int s,char *host)
{
  char *p;
  int i;    
  int numbytes;
  struct sockaddr_in sock;
  struct hostent *he;


  if ((he=gethostbyname(host)) == NULL) 
    {
      perror("gethostbyname()");
      exit(1);
    }

  sock.sin_family = AF_INET;
  sock.sin_port = htons(port);
  sock.sin_addr =  *((struct in_addr *)he->h_addr);  
  bzero(&(sock.sin_zero), 8);

  if (connect(s, (struct sockaddr *)&sock, sizeof(struct sockaddr)) == ERROR) 
    {
	perror("connect()");
    }
  else
    if ((send(s, message, strlen(message), 0)) == ERROR) 
      { 
        perror("send()");
      }
    else
      if ((numbytes=recv(s, buf, MAXDATASIZE, 0)) == ERROR)
        {
          perror("recv()");
        } 
  
  close(s);
  return buf;
}

