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
# https://perlmaven.com/checking-the-whois-record-of-many-domains
4
 
5
use strict;
6
use warnings;
7
use 5.010;
8
 
9
use File::Which; # apt-get install libfile-which-perl
10
 
11
my $whois = which 'whois';
12
my $outPath = 'whois';
13
 
14
unless ( defined $whois ) { # we don't have it, so use Perl's implementation
15
   use Net::Whois::Raw; # apt-get install libnet-whois-raw-perl
16
   $Net::Whois::Raw::CHECK_FAIL = 1;
17
   $Net::Whois::Raw::OMIT_MSG = 1;
18
}
19
 
20
mkdir $outPath unless -d $outPath;
21
 
22
while ( my $domain = <> ) {
23
  chomp $domain; 
24
  next if $domain =~ m/arpa$/; # skip rdns entries
25
  warn "ERROR in [$domain], not processing\n" if $domain !~ m/^[a-z0-9-]+\.[a-z0-9-]+$/;
26
  my $outFile = "$outPath/$domain.whois";
27
  print STDERR "$domain\t";
28
  if ( -e $outFile ) {
29
     print STDERR "Already exists, skipping\n";
30
     next;
31
  }
32
  if ( defined $whois ) {
33
     `$whois $domain > $outFile`;
34
  } else {
35
     my $data = whois($domain);
36
     open OUT,">$outFile" or die "Could not write to $outFile: $!\n";
37
     print OUT $data;
38
     close OUT;
39
  }
40
  if ($domain =~ /\.org$/) {
41
      print STDERR "Waiting 16 seconds to avoid rate limit\n";
42
      sleep 16;
43
  } else {
44
     print STDERR "Waiting 1 second before next one\n";
45
     sleep 1;
46
  }
47
}
48
 
49