得到自己的IP地址 (2001年4月24日)
网友更新 分类:Internet 作者: zhuhongqing(推荐) 推荐:zhuhongqing 阅读次数:403
(http://www.codesky.net)
--------------------------------------------------------------------------------
function GetIPAddress: string;
var
phoste:PHostEnt;
Buffer:array[0..100] of char;
WSAData:TWSADATA;
begin
result:='';
if WSASTartup($0101, WSAData) 0 then exit;
GetHostName(Buffer,Sizeof(Buffer));
phoste:=GetHostByName(buffer);
if phoste = nil then
begin
result:='127.0.0.1';
end
else
result:=StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
WSACleanup;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=GETIPAddress;
end;