PDA

Ver la Versión Completa : Codigo para detectar la IP Real


Vultur
11-02-2005, 19:22:47
Hola

En base a lo publicado http://www.clubdelphi.com/foros/showthread.php?t=148&highlight=real por Hector hice una version para Builder C++. Estoy trabajando con la version 6.0

En el cliente pongo Host: www.zoneedit.com (http://www.zoneedit.com/) y 80 como puerto.

Luego pongo el siguiente codigo:

void __fastcall TForm1::ClientSocket1Connect(TObject *Sender,
TCustomWinSocket *Socket)
{
ClientSocket1->Socket->SendText("GET /checkip.html HTTP/1.1\r\n");
ClientSocket1->Socket->SendText("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*\r\n");
ClientSocket1->Socket->SendText("Accept-Language: es-ar\r\n");
ClientSocket1->Socket->SendText("Accept-Encoding: gzip, deflate\r\n");
ClientSocket1->Socket->SendText("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)\r\n");
ClientSocket1->Socket->SendText("Host: www.zoneedit.com\r\n (http://www.zoneedit.com/r/n)");
ClientSocket1->Socket->SendText("Connection: Keep-Alive\r\n\r\n");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
int pos, cont;
String text,DirIP;
text = ClientSocket1->Socket->ReceiveText();
if(pos = text.Pos("Current IP Address: ")){
DirIP =text.SubString(pos+20, 16); //Me aseguro que cubra desde una IP 1.1.1.1 a 255.255.255.255
pos = DirIP.Pos("\r");
text=DirIP.SubString(1,pos-1);
Memo1->Text = text;
}
}
//---------------------------------------------------------------------------

Asi obtengo la IP de la maquina. Esto se podria adaptar a otros lugares que publican la IP propia facilmente.

El codigo que se le envia al servidor de HTTP lo saque creando un server y vendo que le enviaba el navegador para obtener una respuesta. Seguramente hay cosas que se pueden sacar, pero como no se nada de HTTP no me puse a probar.

Saludos

Luis