function GetLocalIPAddr:string;
var
pBuf: pointer;
RemoteHost : PHostEnt; (* No, don't free it! *)
liTemp : longint;
wsData: TWSAData;
begin
pBuf := NIL;
try
WSAStartup(2, wsData);
Getmem(pBuf,255);
GetHostName(pBuf,255); (* this one maybe without domain *)
RemoteHost:=Winsock.GetHostByName(pBuf);
if RemoteHost=NIL then
liTemp:=winsock.htonl($7F000001) (* 127.0.0.1 *)
else
liTemp:=longint(pointer(RemoteHost^.h_addr_list^)^);
finally
if pBuf <> NIL then Freemem(pBuf,255);
WSACleanup;
end;
liTemp := Winsock.ntohl(liTemp);
if liTemp = $7F000001 then
Result := ''
else
Result := IntToStr((liTemp shr 24) and $000000FF) + '.' +
IntToStr((liTemp shr 16) and $000000FF) + '.' +
IntToStr((liTemp shr 8) and $000000FF) + '.' +
IntToStr(liTemp and $000000FF);
end;