Subversion Repositories sysadmin_scripts

Rev

Blame | Last modification | View Log | Download | RSS feed

#! /usr/bin/env perl

use strict;
use warnings;

use Net::DNS;

my $RR_DIR = '/etc/bind/SEC';
my @nameServers = qw/9.9.9.9 1.1.1.1 8.8.8.8 8.8.4.4 149.112.112.112 208.67.222.222 208.67.220.220 1.0.0.1 64.6.64.6 64.6.65.6/;

sub getNSRecords {
   my $domain = shift;
   use Net::DNS;
   # run the following with a name server randomly chosen from @nameServers
   my $res   = Net::DNS::Resolver->new (nameserver => ($nameServers[rand @nameServers]) );
   my $reply = $res->query($domain, "NS");
   my @result = ();
 
   if ($reply) {
      foreach my $rr (grep { $_->type eq "NS" } $reply->answer) {
         #print $rr->nsdname, "\n";
         push @result,$rr->nsdname;
      }
   } else {
      warn "query failed for [$domain]: ", $res->errorstring, "\n";
   }
   return \@result;
}


my @domains = `ls $RR_DIR`;
chomp @domains;

#print join( "\n", @{ &getNSRecords( "dailydata.net" ) }) . "\n";
#die;

my %results;
my $count = 0;

foreach my $domain (sort @domains) {
   print STDERR '.';
   next if $domain =~ m/\.arpa$/;
   my $ns = &getNSRecords( $domain );
   if ( $ns && scalar (@$ns) ) {
      foreach my $thisNS ( @$ns ) {
         push @{ $results{$thisNS} }, $domain;
      }
   } else {
      push @{ $results{'Unknown'} }, $domain;
   }
   sleep(1);
#   last if $count++ > 10;
}

foreach my $ns ( sort keys %results ) {
   print "$ns\n";
   print "\t", join( "\n\t", @{ $results{$ns} } ) . "\n";
}

1;