• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

retriving the computer of another pc given the ip address

how do you retrieve the computer name of another pc given the ip address only?
0
khangski
Asked:
khangski
  • 2
1 Solution
 
geobulCommented:
Hi,

Try this:

uses Winsock;

function GetRemoteHostName(IPAddr : string) : string;
var
  wsdata : TWSAData;
  he : PHostEnt;
  ip : TInAddr;
begin
  WSAStartup(MakeWord(1, 1), wsdata);
  ip.S_addr := inet_addr(PChar(IPAddr));
  he := gethostbyaddr(@ip.S_un_b, 4, AF_INET);
  if he<>nil then
    Result := string(he.h_name)
  else
    Result := IntToStr(WSAGetLastError);
  WSACleanup();
end;

// usage:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetRemoteHostName('192.0.0.1'));
end;

Regards, Geo
0
 
khangskiAuthor Commented:
thanks man...
0
 
geobulCommented:
You are welcome ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now