Yo llamo a una página que me devuelve la IP. En este ejemplo, la página devuelve 'Current IP Address: 87.111.157.240'.
Una vez obtengo esa cadena, tomo la parte que me interesa.
Ya que el texto podría cambiar en algún momento, pues no es mi página y por lo tanto no controlo su contenido, solo tomo los datos nométricos y los puntos.
Código Delphi
[-]
function DameIPPublica: string;
var
HTMLBody : string;
i : integer;
IdHTTP : TIdHTTP;
begin
Result := '';
try
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
if IsNumeric(HTMLBody[i]) or (HTMLBody[i] = '.') then
Result := Result + HTMLBody[i];
finally
IdHTTP.Free;
end;
end;
except
Result := '';
end;
end;
Si tienes una web, podrías hacer un apartado en ella que devolviera exáctamente el texto que te interese mediante un pequeño script PHP:
Código PHP:
<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo $ip;
?>