I seem to be getting quite a few letters from various registrars wanting me to renew domains I own. I was a bit worried that one would expire behind my back so I whipped up this quick script to print out the expiry date for all my domains. The good news is that I don't have to worry until 2003 sometime :)
#!/usr/bin/perl
my $i = 1;
my %month = map { $_ => $i++ } qw/jan feb mar apr may jun jul aug sep oct nov dec/;
my %domain = ();
DOMAIN: while () { chomp; next if /^\s*$/; my @whois = `whois $_`; LINE: foreach my $line (@whois) { if ($line =~ /expire/i) { my $date; if ($line =~ /(\d\d)-([a-zA-Z]+)-(\d{2,4})/) { $date = join '-', $1, sprintf('%02d', $month{lc($2)}), $3; } elsif ($line =~ /(\d\d\d\d-\d\d-\d\d)/) { $date = join '-', reverse split /-/, $1; } if ($date) { $domain{$_} = $date; next DOMAIN; } } } printf "Error: couldn't find expire date for %s:\n", $_; }
foreach (sort keys %domain) { printf "%s expires on %s\n", $_, $domain{$_}; }
__DATA__ .. DOMAINS HERE ..
my $i = 1;
my %month = map { $_ => $i++ } qw/jan ... dec/;
my %month;
@month{ qw/jan ... dec/ } = 1..12;
DOMAIN: while (<DATA>) {
chomp;
next if /^\s*$/;
my @whois = `whois $_`;
LINE: foreach my $line (@whois) {
if ($line =~ /expire/i) {
my $date;
if ($line =~ /.../) {
$date = join '-', $1, ...;
} elsif ($line =~ /.../) {
$date = join '-', reverse, ...;
}
if ($date) {
$domain{$_} = $date;
next DOMAIN;
}
}
}
printf "Error: ...\n", $_;
}
for my $domain ( grep /\S/, <DATA> ) {
chomp $domain;
for ( grep /expire/i, `whois $domain` ) {
if ( /.../ ) {
$domain{$domain} = join '-', $1, ...;
last;
}
if ( /.../ ) {
$domain{$domain} = join '-', reverse, ...;
last;
}
}
printf "Error: ...\n", $domain;
}