Tuesday, August 19, 2008

DNS Resolver

I had a list of domains that needed their MX records updated. I first wanted to make sure that our DNS servers were authoritative for those zones. I used Perl and the Net::DNS CPAN module to figure out the NS records for each domain.
#!/usr/bin/perl

use Net::DNS;

my $resolver = Net::DNS::Resolver->new;
my $query = "";
my $domain = "";

open(FILE, "</tmp/domains.txt");
while() {
  chomp;
  $domain = $_;
  $query = $resolver->query($domain, "NS");
  print $domain;
  if($query) {
    foreach my $rr ($query->answer) {
      next unless $rr->type eq "NS";
      print ",", $rr->nsdname;
    }
    print "\n";
  } else {
    print ",DOES NOT RESOLVE\n";
  }
}

Labels: ,

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home