/* SpyWeb $gcc -o spyweb spyweb.c Utilidad que verifica que servidor se esta ejecutando, enviando el request de la cabecera. c0d3d by Spy]-[unt3R */ #include #include #include #include #include #include #include #include #include #define PORT 80 #define MAX 2000 int main(int argc, char *argv[]){ int sockfd; int numbytes; int port; struct sockaddr_in server_addr; struct hostent *he; char *header_request; char buffer[MAX]; header_request="HEAD / HTTP/1.0\n\n"; printf("[--- SpyWeb Determina que servidor se esta ejecutando ---]\n"); printf("[--- c0d3d by Spy]-[unt3R (spyhunt3r@yahoo.com) ---]\n"); printf("[--- -------------------------------------------------- ---]\n"); if(argc<2){ printf("[--- Uso:spyweb [port] ---]\n"); exit(1); } if(argc>2) port=atoi(argv[2]); else{ printf("[--- Usando puerto 80 por defecto ---]\n\n"); port=PORT; } if((he=gethostbyname(argv[1]))==NULL){ printf("[--- Error en gethostbyname() ---]\n"); printf("[--- Host no encontrado! ---]\n"); exit(1); } printf("[1] gethostbyname() resuelto!\n"); if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1){ printf("Error al crear el socket\n"); exit(1); } printf("[2] socket creado:%d\n", sockfd); server_addr.sin_family=AF_INET; server_addr.sin_port=htons(port); server_addr.sin_addr=*((struct in_addr *)he->h_addr); bzero(&(server_addr.sin_zero), 8); if(connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr))==-1){ printf("[--- Error en connect() ---]\n"); printf("[--- Puerto no disponible ---]\n"); exit(1); } printf("[3] status:conectado\n"); send(sockfd, header_request, strlen(header_request), 0); printf("[4] mensaje enviado!\n"); if((numbytes=recv(sockfd, buffer, sizeof(buffer),0))==-1){ printf("[--- Error en recv() ---]\n"); exit(1); } buffer[numbytes] ='\0'; printf("%s\n", buffer); close(sockfd); printf("[5] cerrando socket!\n"); return 0; }