Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get host name from IP address!

Posted on 1999-01-19
7
Medium Priority
?
289 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
Technology Partners: 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 90 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

609 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