var
wVersionRequested: WORD;
wsaData: TWSAData;
P: PHostEnt;
S: array[0..128] of char;
p2: PChar;
begin
{创建 WinSock}
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
{得到计算机名称}
GetHostName(@s,128);
p := GetHostByName(@s);
Edit1.Text := p^.h_Name;
{得到机器IP地址}
p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
Edit2.Text := p2;
{释放 WinSock}
WSACleanup;
end;