代碼: 選擇全部
procedure Tform1.Button1Click(Sender: TObject);
var
WSAData: TWSAData;
HostEnt: PHostEnt;
Name, Address: string;
begin
WSAStartup(2, WSAData);
SetLength(Name, 255);
Gethostname(PChar(Name), 255);
SetLength(Name, StrLen(PChar(Name)));
HostEnt := gethostbyname(PChar(Name));
with HostEnt^ do
Address := format('%d.%d.%d.%d',[Byte(h_addr^[0]), Byte(h_addr^[1]),Byte(h_addr^[2]), Byte(h_addr^[3])]);
WSACleanup;
showmessage( Name );
showmessage( Address );
end;