Feltros has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I currently keep a lot of logs of people who visit my website for statistical data among other reasons. I'm looking however to improve on how much data I can collect about the people who visit by retrieving their hostname information - I am however finding it incredibly hard to find out how to do this in perl. Any help? I'm looking for something that turns the usual xx.xx.xx.xx into its blah.blah.hostname.isp.whatever hostname. Thanks for the help.

Replies are listed 'Best First'.
Re: Resolving an IP to its hostname
by jwkrahn (Abbot) on Aug 25, 2006 at 20:16 UTC
    $ perl -MSocket -le'$_ = gethostbyaddr inet_aton( q[216.109.112.135] ) +, AF_INET; print' w2.rc.vip.dcn.yahoo.com
Re: Resolving an IP to its hostname
by andyford (Curate) on Aug 25, 2006 at 20:21 UTC
Re: Resolving an IP to its hostname
by jpeg (Chaplain) on Aug 26, 2006 at 13:07 UTC
    If you're using Apache and your site is not too busy you can set HostnameLookups On in your httpd.conf. Watch out and make sure it doesn't slow down your site.
    --
    jpg
Re: Resolving an IP to its hostname
by RobPayne (Chaplain) on Aug 27, 2006 at 19:39 UTC
    You have gotten a couple of responses to your question. I wanted to point out that there is a cpan module that might provide you more options (Net::DNS) for DNS resolution than inet_aton. Net::DNS implements another DNS resolver that can be used if you want to do things like control which name server or servers are used to resolve DNS queries.