O
oyxb1
Unregistered / Unconfirmed
GUEST, unregistred user!
我想在终端上运行程序取得终端上的ip地址,但是得到的是终端服务器的ip,我的取本地ip
地址的函数如下:
function GetLocalIP(var LocalIp: string): Boolean;//获得IP地址函数
var
HostEnt: PHostEnt;
Ip: string;
addr: pchar;
Buffer: array [0..63] of char;
GInitData: TWSADATA;
begin
Result := False;
try
WSAStartup(2, GInitData);
GetHostName(Buffer, SizeOf(Buffer));
HostEnt := GetHostByName(buffer);
if HostEnt = nil then Exit;
addr := HostEnt^.h_addr_list^;
ip := Format('%d.%d.%d.%d', [byte(addr [0]),
byte (addr [1]), byte (addr [2]), byte (addr [3])]);
localip := Ip;
Result := True;
finally
WSACleanup;
end;
end;
请问如何取到终端本地的ip,请高手不吝赐教,谢谢!
地址的函数如下:
function GetLocalIP(var LocalIp: string): Boolean;//获得IP地址函数
var
HostEnt: PHostEnt;
Ip: string;
addr: pchar;
Buffer: array [0..63] of char;
GInitData: TWSADATA;
begin
Result := False;
try
WSAStartup(2, GInitData);
GetHostName(Buffer, SizeOf(Buffer));
HostEnt := GetHostByName(buffer);
if HostEnt = nil then Exit;
addr := HostEnt^.h_addr_list^;
ip := Format('%d.%d.%d.%d', [byte(addr [0]),
byte (addr [1]), byte (addr [2]), byte (addr [3])]);
localip := Ip;
Result := True;
finally
WSACleanup;
end;
end;
请问如何取到终端本地的ip,请高手不吝赐教,谢谢!