Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about resolving an ip

Status
Not open for further replies.

emilybartholomew

Technical User
Aug 3, 2001
82
US
Hi-

I want to be able to get the domain of the ip requesting infomration from my webpage. Basically I want to show one thing if it's a .gov domain, and another if it's anything else. I've been able to obtain the ip number address with
my $ip = $ENV{'REMOTE_ADDR'};

Is there a way to resolve this and get the information I'm interested in? Reading through post here I found a little information on Net::DNS, but am not smart enough to figure it out.

Thanks-
emily
 
I haven't used the REMOTE_HOST environment variable, but does that give you what you want?
 
I'd have to agree with raider. I have a script on my blog that logs the ip and remote hostname. All my logs show that REMOTE_HOST is a resolved hostname for the specific host. Steve Kiehl
webmaster@nanovox.com
 
I just tested REMOTE_HOST and it seems to give me a numeric address.

However, after a little more snooping around I found a script here: called lrdns.pl (written by Matti Tukiainen <ktmatu@usa.net>
) that works like a charm. It converts numeric ips to a name. The only thing I have a question about is the &quot;use Socket&quot; directive. Does this compromise security at all? I've never used it, and don't know much about it.
 
See perldoc Net::hostent -enter-

Code:
#!/usr/local/bin/perl
use Net::hostent;
use Socket;
$host = '208.201.239.56'; # [URL unfurl="true"]www.perl.com[/URL]
unless ($h = gethost($host)) 
    { warn &quot;$0: no such host: $host\n&quot;; }
    
printf &quot;\n%s is %s%s\n&quot;, 
    $host, 
    lc($h->name) eq lc($host) ? &quot;&quot; : &quot;*really* &quot;,
    $h->name;

The perldocs show a full example of using the modules. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top