Zusatz:
mit Delphi Rio würde ich es so in etwa machen:
Delphi-Quellcode:
uses IdStack;
//lokale
function GetIP : String;
begin
TIdStack.IncUsage;
try
Result := GStack.LocalAddress;
finally
TIdStack.DecUsage;
end;
end;
//vom host
function GetIP(const HostName: string): string;
var
WSAData: TWSAData;
R: PHostEnt;
A: TInAddr;
begin
Result := IPNULL; // '0.0.0.0'
WSAStartup($101, WSAData);
R := Winsock.GetHostByName(PAnsiChar(AnsiString(HostName)));
if Assigned(R) then
begin
A := PInAddr(r^.h_Addr_List^)^;
Result := WinSock.inet_ntoa(A);
end;
end;