Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  MS-Wallet w/BrowserHawk
     [next Lesson]  BrowserHawk - Frame support

How to resolve IP address to host names

Have you ever looked at an IP address and wondered where the user came from?  Take 198.137.240.91 for example.  Certainly "www.whitehouse.gov" has quite a lot more meaning.

At one time or another you'll likely find yourself wanting to resolve IP addresses to host names.  This is known in the biz as "reverse DNS lookups".  So why would someone want to resolve an IP address?  Well there are several possible uses for this information, but for this example we'll talk about using this information to help reduce fraud on your web site.

For example, consider for a moment the issue of credit card fraud.  Certainly providing fraudulent credit card information (or using someone elses card) over the Internet seems much easier than doing the same in person.  This is because it seems easy to hide behind the anonymous nature of an HTTP connection.  What the user may not realize, however, is that based on their IP address you can likely determine who their their employer or ISP is - and can use that information to track down someone providing fradulent credit card information or abusing your site in other ways.

The host name, therefore, can serve as a decent deterrent by showing the host name to the visitor.  This way they realize it is possibly that their identify could be determined based on this information.  For example, showing someone with dishonest intentions that you know they are connected through "pop5.erols.net" may make them think twice before entering fraudulent credit card information.  Afterall, it may not prove all that difficult for the authorities to obtain records from their ISP to determine their identity.

As was mentioned earlier, there are several possible uses for this information. Whatever your reasons may be, BrowserHawk makes it easy to to obtain the host name for the current visitor or for any other IP address you'd like to look up.

To determine the host name for the current site visitor, simply call the BrowserHawk ResolveIP method as demonstrated in the example below:

   filename=/browserhawk/resolveip_curuser.asp

<Test Script Below>


<html>

<head>
<title>Resolve IP</title>
</head>

<body>

<p>Hello user connected from <%
set bh = Server.CreateObject("cyScape.browserObj")
hostname = bh.ResolveIP
if hostname <> "" then
   response.write hostname
else
   response.write "Unknown"
end if
%> </p>

<p>%&gt;</p>
</body>
</html>

Similarly, you can also obtain the host name for any given IP address as well.   You simply call the ResolveIP method and pass in the IP address to be resolved as a parameter to the method.  This is demonstrated in the example below:

   filename=/browserhawk/resolveip_specip.asp

<Test Script Below>


<html>

<head>
<title>Resolve IP</title>
</head>

<body>
<%
ipToLookup = "198.137.240.91"
%>

<p>The host name for <%=ipToLookup%> is <%
set bh = Server.CreateObject("cyScape.browserObj")
hostname = bh.ResolveIP(ipToLookup)
if hostname <> "" then
   response.write hostname
else
   response.write "Unknown"
end if
%> </p>

<p>%&gt;</p>
</body>
</html>

Copyright (c) 1999 cyScape, Inc.  All rights reserved.  This material may not be published, distributed, or reprinted without written consent from cyScape.

There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.