Listing08_Query_To_Test_DNS (Perl)

This code can be found in Chapter 8 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4

use strict;
use Net::DNS;

my $target = 'dc1.xyz.com';
my $res = Net::DNS::Resolver->new();
   $res->nameservers($target);
my $query = $res->search("127.in-addr.arpa", "NS");
if ($query) {
   foreach my $rr ($query->answer) {
      next unless $rr->type eq "NS";
      print "Received response: ",$rr->nsdname,"\n";
   }
}
else {
   die "NS query failed: ", $res->errorstring, "\n";
}

This code has been viewed 616 times.

New from the creators of TechTasks.com: StatSheet.com