On 03/07/2013 10:21 AM, shawn wilson wrote:
use Data::Dumper;
use Net::DNS::Resolver;

my $dns = Net::DNS::Resolver->new;

print rev_ip('8.8.8.8') . "\n";

sub rev_ip
{
   my ($ip) = @_;

   my $packet = $dns->search($ip);
   my @authority = $packet->authority;
   my $string = join ', ', map { $_->name } @authority;
   return "[$ip] $string";
}


Your results may vary, but for the vast majority of resolvers out there, you are not going to get any authority records - because most of them are not authoritative.

You probably want to be looking in the ANSWER.

Also - since you gave it the name - you already knew that part - it's what you gave the resolver. What you want is the rdatastr method (perldoc Net::DNS::RR)


sub rev_ip
{
  my $string = join ', ', map { $_->rdatastr } $dns->search($_[0])->answer;
  return "[$_[0]] $string";
}

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to