Gossamer Forum
Home : General : Perl Programming :

IP --> host address

Quote Reply
IP --> host address
Does anyone can tell me the way to translate an IP address in a host name?

ex:

193.199.299.3 ---> my.domain.com


thanks in advance



------------------
------
Lepo
Quote Reply
Re: IP --> host address In reply to
Hi Lepo75,

I'm not sure how to do this personally, but I believe the AXS tracker found on:
http://www.xav.com/scripts/axs/index.html
Has this ability built in, his program is free for personal and educational use. You may want to look at his code for this script, to find your answer. I believe it involves making a call to a DNS server that will return a match for the IP as a Domain Name...I'm not sure though.

Hope this helps

Rod
Quote Reply
Re: IP --> host address In reply to
Here's a lookup routine taken from http://www.modperl.com/...verse_DNS_Resolution

Code:
sub lookup {
my $ip = shift;
return $ip unless $ip=~/\d+\.\d+\.\d+\.\d+/;
unless (exists $CACHE{$ip}) {
my @h = eval <<'END';
alarm(TIMEOUT);
my @i = gethostbyaddr(pack('C4',split('\.',$ip)),2);
alarm(0);
@i;
END
$CACHE{$ip} = $h[0] &#0124; &#0124; undef;
}
return $CACHE{$ip} &#0124; &#0124; $ip;
}

Hope that helps,

Alex