function GetDynIP(HostName: string = ''): string;
var
IP: string;
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array[0..63] of Char;
I: Integer;
GInitData: TWSAData;
begin
WSAStartup($101, GInitData);
IP := '0.0.0.0';
if HostName = '' then
GetHostName(Buffer, SizeOf(Buffer))
else
StrPCopy(Buffer, HostName);
phe := GetHostByName(buffer);
if phe = nil then
begin
Result := IP;
Exit;
end;
pPtr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pPtr^ <> nil do
begin
IP := inet_ntoa(pptr^^);
Inc(I);
end;
WSACleanup;
Result := IP; //如果上网则为上网ip否则是网卡ip
end;
这也是我在dfw上收集的.