Solved

Get host name from IP address!

Posted on 1999-01-19
7
267 Views
Last Modified: 2010-04-06
How to do it?
0
Comment
Question by:mingwei
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:BlackMan
ID: 1362436
Use the GetHostByAddr function, like this:

uses Winsock;

function HostByAddr(AddrStr: String): String;
  Addr: TInAddr;
  Host: PHostEnt;
begin
  AddrStr := '136.148.3.10';
  Addr.s_addr := Inet_Addr(PChar(AddrStr));
  Host := GetHostByAddr(@Addr.s_addr,4,PF_INET);
  Result := Host^.h_name;
end;

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1362437
Oops, remove the line AddrStr := '136.148.3.10'; from the function...
0
 

Author Comment

by:mingwei
ID: 1362438
GetHostByAddr(@Addr.s_addr,4,PF_INET);
return nil
0
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!

 
LVL 7

Accepted Solution

by:
BlackMan earned 30 total points
ID: 1362439
Sorry, I cut it out of a larger unit. You need to initialize WinSock first to make it work.

uses Winsock;

Var
  VerReqd      : Word;
  WSAData      : TWSAData;
  WSErr      : Word;

function HostByAddr(AddrStr: String): String;
Var
  Addr: TInAddr;
  Host: PHostEnt;
begin
  VerReqd := $0101;
  WSErr := WSAStartup(VerReqd, WSAData);

  Addr.s_addr := Inet_Addr(PChar(AddrStr));
  Host := GetHostByAddr(@Addr.s_addr,4,PF_INET);
  Result := Host^.h_name;
end;


0
 

Author Comment

by:mingwei
ID: 1362440
But I want to say this way just return the hosts name
from local HOSTS files.
If I want to get hosts name from Internet how can I read
information from IP pack?
If you have any source tell me about that!
Thanks a lot.

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1362441
This code is not specific to the HOSTS file, it uses the normal TCP/IP conventions. This means that if you want to use it on www addresses, you must have a proper DNS configured in your TCP/IP settings, which you'd probably allready have if you are able to access www.experts-exchange.com. You need to be connected to read the names, there is no cache with names/addresses..

0
 

Author Comment

by:mingwei
ID: 1362442
Oh,I know!
Very thanks.
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 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