Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert IPs in Host names

Posted on 2000-03-12
2
Medium Priority
?
182 Views
Last Modified: 2010-04-04
Hi ,
I have the IPs of some servers and I wish to know the host names .
How can I do it ?
Can I know the location , too ?

Regards,
Nick

I wish to use this informations  in a traceroute program .
0
Comment
Question by:ginsonic
2 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 165 total points
ID: 2611206
Try this:

uses WinSock;

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

function GetIPAddress(name : string) : string;
var wsdata : TWSAData;
    he : PHostEnt;
    ss : pchar;
    ip : TInAddr;
begin
  WSAStartup(MakeWord(1, 1), wsdata);
  he := gethostbyname(pchar(name));
  if he<>nil then
  begin
    ip.S_addr := integer(pointer(he^. h_addr_list^)^);
    ss := inet_ntoa(ip);
    Result := string(ss);
  end;
  WSACleanup();
end;
0
 
LVL 1

Expert Comment

by:nrico
ID: 2611536
Also, if you connect to them using a TClientSocket, you can find the name int ClientSocket1.Socket.RemoteHost;

Rico
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question