procedure TForm1.Button4Click(Sender: TObject); //已知计算机名,得到IP地址。
var //得不到IP地址,就是不通
WSAData: TWSAData;
HostEnt: PHostEnt;
sComputerName, sIP: string;
begin
button4.Enabled :=false;
sComputername:=edit1.text;
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(sComputerName));
if HostEnt <> nil then
begin
with HostEnt^ do
sIP := Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
end;
WSACleanup;
edit2.text:=sIP;
button4.Enabled :=true
end;