Here's a quick perl snippet for performing reverse DNS lookups.
It requires Net::IP and Net::DNS which should already be installed in most perl installations.
One of these days I'm going to get around to wrapping this with CGI, but for now it works quick and easy using the command line.
Simply run ip.pl followed by the ip address you are looking for.


1<br /> 2#!/usr/bin/perl<br /> 3use strict;<br /> 4use warnings;<br /> 5use Net::IP;<br /> 6use Net::DNS;<br /> 7my $ip = new Net::IP($ARGV[0],4);<br /> 8print $ip->reverse_ip()."\n";<br /> 9print "Resolving ...\n";<br /> 10my $res = Net::DNS::Resolver->new;<br /> 11my $answer = $res->query($ip->reverse_ip(),'PTR');<br /> 12my $namer = $answer->{'answer'}[0];<br /> 13print "PTR Name: $namer->{'ptrdname'}\n";<br />
I had a little bit of trouble putting this together being that $answer is an array just in case you get multiple results (Multiple results is perfectly reasonable, and necessary in shared hosting environments). This script simply outputs the first result. I don't know of any hosts that actually do reverse dns properly in order to test multiple results, and my own inaddr.arpa addresses are resolved by my data center provider.
Essentially, I'm simply reversing the IP address, then running a DNS query for the PTR record. Sounds pretty simple, but it took a bit of reading up on things in order to figure things out.
Update - I actually did put a CGI wrapper around this thing. You can see perform a Reverse IP Lookup online quickly and easily to gain a better understanding of what this is. At some point in the near future, I'll post the full script for download. You can also get a sneak peek at my site redesign.
Talk About Reverse IP Lookup using Perl
