Fórum Capturar IP externo #272401
15/03/2005
0
Tenho esta funcao mas pega o IP interno:
function GetLocalIP : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := ´´;
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));
result := StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
Obrigado
Estanieski
Curtir tópico
+ 0Post mais votado
15/03/2005
uses
Winsock;
{...}
function getIPs: Tstrings;
type
TaPInAddr = array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array[0..63] of Char;
I: Integer;
GInitData: TWSAData;
begin
WSAStartup($101, GInitData);
Result := TstringList.Create;
Result.Clear;
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then Exit;
pPtr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pPtr^[I] <> nil do
begin
Result.Add(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
//==Chame assim
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines := GetIps;
end;Sanses
Sanses
Gostei + 2
Mais Posts
26/01/2016
Cristiano
mas estou usando seu codigo no delphi xe8 e esta dando erro na linha que tem a palavra Buffer, gostaria de saber se tenho que declarar algo na Uses ou alguma variavel. Aguardo resposta, email: cristiano19020@gmail.com
Gostei + 0
04/08/2016
Marcelo Stefaniak
var Buffer: pansichar;
Gostei + 0
08/12/2016
Quality Sistemas
Buffer : array [0 .. 63] of Ansichar;
Gostei + 0
03/11/2017
Gladson Reis
gladson @ stonestecnologia com br
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)