Subversion Repositories sysadmin_scripts

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
74 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
6
use Net::DNS;
7
 
8
my $RR_DIR = '/etc/bind/SEC';
9
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/;
10
 
11
sub getNSRecords {
12
   my $domain = shift;
13
   use Net::DNS;
14
   # run the following with a name server randomly chosen from @nameServers
15
   my $res   = Net::DNS::Resolver->new (nameserver => ($nameServers[rand @nameServers]) );
16
   my $reply = $res->query($domain, "NS");
17
   my @result = ();
18
 
19
   if ($reply) {
20
      foreach my $rr (grep { $_->type eq "NS" } $reply->answer) {
21
         #print $rr->nsdname, "\n";
22
         push @result,$rr->nsdname;
23
      }
24
   } else {
25
      warn "query failed for [$domain]: ", $res->errorstring, "\n";
26
   }
27
   return \@result;
28
}
29
 
30
 
31
my @domains = `ls $RR_DIR`;
32
chomp @domains;
33
 
34
#print join( "\n", @{ &getNSRecords( "dailydata.net" ) }) . "\n";
35
#die;
36
 
37
my %results;
38
my $count = 0;
39
 
40
foreach my $domain (sort @domains) {
41
   print STDERR '.';
42
   next if $domain =~ m/\.arpa$/;
43
   my $ns = &getNSRecords( $domain );
44
   if ( $ns && scalar (@$ns) ) {
45
      foreach my $thisNS ( @$ns ) {
46
         push @{ $results{$thisNS} }, $domain;
47
      }
48
   } else {
49
      push @{ $results{'Unknown'} }, $domain;
50
   }
51
   sleep(1);
52
#   last if $count++ > 10;
53
}
54
 
55
foreach my $ns ( sort keys %results ) {
56
   print "$ns\n";
57
   print "\t", join( "\n\t", @{ $results{$ns} } ) . "\n";
58
}
59
 
60
1;