Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Codigo para detectar la IP Real (https://www.clubdelphi.com/foros/showthread.php?t=18437)

Vultur 11-02-2005 19:22:47

Codigo para detectar la IP Real
 
Hola

En base a lo publicado http://www.clubdelphi.com/foros/show...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 y 80 como puerto.

Luego pongo el siguiente codigo:

Código:

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");
  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


La franja horaria es GMT +2. Ahora son las 22:45:53.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi