Solved

Get host name from IP address!

Posted on 1999-01-19
7
256 Views
Last Modified: 2010-04-06
How to do it?
0
Comment
Question by:mingwei
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 211
Delphi application Soap connection 5 96
find a node in VST 2 63
TEMBEDDEDWB how can i change its user agent ? 8 48
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now