[C] Obtener código fuente de una web [GNU/Linux]

Iniciado por S[e]C, Abril 02, 2010, 11:50:43 AM

Tema anterior - Siguiente tema

0 Miembros y 2 Visitantes están viendo este tema.

Abril 02, 2010, 11:50:43 AM Ultima modificación: Febrero 08, 2014, 06:12:37 PM por Expermicid
Código: c
#include <stdio.h>  //std I/O
#include <string.h>   //manejo de strings
#include <stdlib.h>   //malloc
#include <netdb.h>  //gethostbyname, structs, recv,send, ...
#include <unistd.h>  //close


#define PORT 80
#define BUFSIZE 1024

int main(int argc, char *argv[])
{
int mi_socket;
struct sockaddr_in *con;
struct hostent *he;
char buffer[BUFSIZE];
char peticion[100];
int i;

if (argc != 3)
{
  fprintf(stderr,"Parametros incorrectos:\nModo de uso: %s <host> <path>\n",argv[0]);
fprintf(stderr,"Ejemplo    : %s www.web.com index.php\n",argv[0]);
  exit(1);
}
sprintf(peticion,"GET /%s/ HTTP/1.0\r\nHost:%s\r\nUser-agent:Mozilla 5.0 Compatible\r\n\r\n",argv[2],argv[1]);

fprintf(stdout,"#===========#Request:#============#\n");
fprintf(stdout,"%s\n",peticion);
fprintf(stdout,"#=================================#\n");
mi_socket=socket(AF_INET,SOCK_STREAM,0);

if(mi_socket==-1)
{
fprintf(stderr,"->Error al crear el socket\n");
exit(1);
}
fprintf(stdout,"->Socket creado\n");
if ((he=gethostbyname(argv[1])) == NULL)
{
       fprintf(stderr,"->Error al obtener informacion de la maquina\n");   
       exit(1);
}
con = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *));
con->sin_family = AF_INET;
con->sin_port = htons(PORT);
con->sin_addr = *((struct in_addr *)he->h_addr);
memset(con->sin_zero,0,8);

if (connect(mi_socket, (struct sockaddr *)con,sizeof(struct sockaddr)) == -1)
{
       fprintf(stderr,"->Error al conectar\n");
       exit(1);
}
fprintf(stdout,"->Socket conectado\n");
send(mi_socket, peticion, strlen(peticion), 0);
fprintf(stdout,"->Peticion enviada\n");
fprintf(stdout,"->Recibiendo respuesta...\n\n");
memset(buffer, 0, sizeof(buffer));
while((i=recv(mi_socket, buffer, BUFSIZE, 0))>0)
{
   fprintf(stdout,"%s",buffer);
   memset(buffer, 0, i); //seteo lo que use del buffer en 0
}
//free(con);     
close(mi_socket);
fprintf(stdout,"->Conexion cerrada\n");
return 0;
}


Citargcc code.c -o code
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login



Serviria para windows?? y otra cosa, con ese programa te bajas los codigos en php??

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Serviria para windows?? y otra cosa, con ese programa te bajas los codigos en php??

No no sirve para windows, pero solo debes cambiar unas librerias, modificar algunas partes del código y ya (en mi blog busca por la etiqueta sockets hay una versión para windows pero con errores para que no hagan copy & paste, esa te puede servir), y no no baja el php, viene siendo como usar el "view source" del navegador.

La utilidad esta, en el para las tools, no se búsquedas automatizadas en el código fuente, y cosas de esa índole .

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login