以下代码格式化出错.
function GetLocalIP: string;
var
WSData: TWSAData;
Buffer: array[0..63] of ansiChar;
HostEnt: PHostEnt;
PPInAddr: ^PInAddr;
IPString: string;
begin
IPString := '';
try
WSAStartUp($101, WSData);
GetHostName(Buffer, SizeOf(Buffer));
HostEnt := GetHostByName(Buffer);
if Assigned(HostEnt) then
begin
PPInAddr := @(PInAddr(HostEnt.H_Addr_List^));
while Assigned(PPInAddr^) do
begin
IPString := string(StrPas(INet_NToA(PPInAddr^^)));
Inc(PPInAddr);
end;
end;
Result := IPString;
finally
try
WSACleanUp;
except
end;
end;
end;
|