想获取本机获取的Internet IP地址?下面的代码就可以了,不管什么conn
type
PPInAddr = ^TPInAddr;
TPInAddr = array [0..10] of PInAddr;
var FLocalIP: string = '';
function LocalIP: string;
var
WSAData: TWSAData;
pHostName: array[0..MAX_COMPUTERNAME_LENGTH] of Char;
HostEnt: PHostEnt;
p: PPInAddr; s: DWord;
begin
if FLocalIP <> '' then
begin
Result := FLocalIP;
Exit;
end;
if WSAStartup($0101, WSAData) <> 0 then //Looking To Use Version 1.1 Of WinSock
raise Exception.Create('WSAStartup: 不能初始化WinSock 1.1');
s := SizeOf(pHostName);
GetComputerName(pHostName, s); //Found a unknown bug when using GetHostName(pHostName, SizeOf(pHostName)): return the Logon UserName!
HostEnt := GetHostByName(pHostName);
if HostEnt = nil then
raise Exception.Create('本机IP获取失败,微机名=' + pHostName) //Fatal
else
begin
p := PPInAddr(HostEnt^.h_addr_list);
Result := StrPas(inet_ntoa(p^[0]^));
end;
WSACleanup;
end;
-----
http://www.8421.org