哥们,这样 function GetLocalIP(var LocalIp: string): Boolean; 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;
VB 有一个控件可以直接得到 "WINSOCK"
PHostEnt,是什么啊?我这不能运行阿~谢谢
uses winsock;var strIP:string; begin if GetLocalIP(strIP) then Caption:=strip; end;
GetLocalIP什么意思啊?我不能运行阿
GetLocalIP 就是 hgf_hb(酸书生) 写的那个函数 我写的是调用这个函数的方法
uses winsock;var strIP:string; begin if GetLocalAddress(strIP) then Caption:=strip; end;说明: Declaration function GetLocalAddress: String;Description The GetLocalAddress method will return the local IP address formatted for sending to an FTP server when initiating a data transfer.
function GetLocalIP(var LocalIp: string): Boolean;
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;
"WINSOCK"
strIP:string;
begin
if GetLocalIP(strIP) then
Caption:=strip;
end;
我写的是调用这个函数的方法
strIP:string;
begin
if GetLocalAddress(strIP) then
Caption:=strip;
end;说明:
Declaration
function GetLocalAddress: String;Description
The GetLocalAddress method will return the local IP address formatted for sending to an FTP server when initiating a data transfer.