Subversion Repositories sysadmin_scripts

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
156 rodolico 1
#! /usr/bin/perl -w
2
 
3
sub getWhois {
4
   my $domain = shift;
5
   my @results;
6
   my $filename = "cache/$domain.whois";
7
   if ( -e $filename ) {
8
      print STDERR "Looking up $domain from cache\n";
9
      open WHOIS,"<$filename" or die "Could not read $filename: $!";
10
      @results = <WHOIS>;
11
      close WHOIS;
12
   } else {
13
      @results = `whois $domain`;
14
      print STDERR "Retrieving $domain from whois\n";
15
      sleep(15);
16
      open WHOIS,">$filename" or die "Could not write to $filename: $!";
17
      print WHOIS @results;
18
      close WHOIS;
19
   }
20
   return @results;
21
}
22
 
23
sub checkDomain {
24
   my $domain = shift;
25
   my $results = join( "\n", getWhois( $domain ) );
26
   my %nameservers;
27
   while ( $results =~ m/Name Server:\s*(.*)$/gm ) {
28
      $nameservers{lc $1} = 1;;
29
   }
30
   return "$domain\t" . (%nameservers ? join( "\t", sort keys %nameservers ) : 'Possibly bad' );
31
}
32
 
33
my @results;
34
while ( my $domain = <> ) {
35
   chomp $domain;
36
   next unless $domain;
37
   push( @results, &checkDomain( $domain ) );
38
}
39
print join( "\n", @results ) . "\n";
40
1;