unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,winsock, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
WSAData:TWSAData;
p
HostEnt;
sIP:string;
InetAddr:dword;
begin
WSAStartup(2, WSAData);
sIP:=edit1.text;
InetAddr:= inet_addr(PChar(sIP));
try
try
p:=GetHostByAddr(@InetAddr, Length(sIP), PF_Inet);
memo1.lines.add('IP地址:'+sIP);
memo1.lines.add('计算机名:'+p^.h_name);
memo1.lines.add('别名:'+string(p^.h_aliases));
memo1.lines.add('地址类型:'+chr(p^.h_addrtype+64));
memo1.lines.add('地址长度:'+inttostr(p^.h_length)+'字节');
memo1.lines.add('---------------------------');
finally
WSACleanup;
//释放资源
end;
except
memo1.lines.add('无法获取与该IP地址对应的计算机名!');
end;
end;
end.