uses {...,}Winsock;
procedure ShowHostName;
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);
ShowMessage(Format('Computer name is ''%s''.', [p^.h_Name]));
{IP地址}
p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
ShowMessage(Format('IP address is %s.',[p2]));
WSACleanup;
end;