Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Saber Ip Pública (https://www.clubdelphi.com/foros/showthread.php?t=80762)

vtdeleon 21-09-2006 19:15:35

Saber Ip Pública
 
Funcion para saber la ip pública. Necesita las unidades IdHTTP y WinInet.

Codigo recogido en el Foro.
Código Delphi [-]
function IP_Publica:string;
  function IsNumeric( T:string ):boolean;
  begin
    Result:=false;
    if (length(T)>0) then
      case T[1] of
          '0'..'9':Result:=true;
      end;
  end;
var
  HTMLBody:string;
  i:integer;
  IdHTTP:TIdHTTP;
begin
  Result:='';
  if   WinInet.InternetGetConnectedState(nil,0)
  then begin
       IdHTTP:=TIdHTTP.Create(Application);
       try
         HTMLBody:=IdHTTP.Get('http://checkip.dyndns.org/');
         for i:=0 to Length(HTMLBody)-1 do begin
             if   IsNumeric(HTMLBody[i])
             or  (HTMLBody[i]='.')
             then Result:=Result+HTMLBody[i];
         end;
       finally
         IdHTTP.Free;
       end;
  end;
end;


La franja horaria es GMT +2. Ahora son las 02:17:35.

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