http://www.perlmonks.org?node_id=739560


in reply to Net::Nslookup PTR lookup help

Personally, I find Net::DNS much easier to use. Consider:

#! /usr/bin/perl -w use strict; use Net::DNS; my $r = Net::DNS::Resolver->new; for my $ip (@ARGV) { my $reverse = join( '.', reverse( split /\./, $ip )) . '.in-addr.a +rpa'; if (my $ap = $r->query( $reverse, 'PTR' )) { for my $pa ($ap->answer) { print "$ip => ", $pa->ptrdname, $/; } } else { print "$ip => NXDOMAIN\n"; } } __OUTPUT__ ./ptr 69.147.76.15 69.147.76.15 => f1.www.vip.re1.yahoo.com

Update: easier... hmmm... let me rephrase that: "gives me finer control over what I want to do". It's a really useful module to have in your toolkit if you ever have to grovel around with CNAME, MX, NS, SOA records and the like.

2nd update: new improved! with error checking!

• another intruder with the mooring in the heart of the Perl