



Esta função retorna IP de conexão com a Internet ( IP do Roteador )
Lembre de dar user de IDHttp
Obs: Essa função pode pausar o processo do seu aplicativo até que
ela receba resposta ou atinja o tempo limite.
Código fonte:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | function GetIPReal: String; var IP: TIdHTTP; Temporario: String; Endereco: String; X: Integer; begin IP := TIdHTTP.Create(nil); try try with IP do begin Temporario := Get('http://checkip.dyndns.org'); for X := 1 to Length(Temporario) do if (CharInSet(Temporario[X], ['0' .. '9', '.'])) then Endereco := Endereco + Temporario[X]; end; Result := Trim(Endereco); except Result := 'ERRO AO RECUPERAR IP'; end; finally IP.Free end; end; |
Exemplo de uso
1 2 3 4 | procedure TForm1.Button1Click(Sender: TObject); begin showmessage(GetIPReal); end; |
Fonte base: http://www.planetadelphi.com.br/dica/7562/-retorna-ip-de-conexao-com-a-internet-(-ip-do-roteador-)–