程序如下:
var
WSData: TWSAData;
Buffer: array[0..63] of Char;
HostEnt: PHostEnt;
PPInAddr: ^PInAddr;
LocalIP: DWord;
IPString: String;
//取本机IP地址
procedure GetIP;
begin
LocalIP:=0;
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:=StrPas(INet_NToA(PPInAddr^^));
LocalIP:=PPInAddr^^.S_Addr;
Inc(PPInAddr);
end;
end;
finally
try
WSACleanUp;
except
end;
end;
end;
//取本机IP地址,返回4字节格式
function GetIPAddress: DWORD;
begin
GetIP;
Result := LocalIP;
end;
//取本机IP地址,返回点分隔字符串格式
function GetLocalIP: String;
begin
GetIP;
Result := IPString;
end;
>> 我想说winipcfg得到的只是网卡在局域网上的IP,不能得到ISP动态分配的IP
上面的代码是我自己写的,
我没测试过是否能得到你要的。。。
试试看先!