Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gav (2710)

gav
  (email not shown publicly)
http://www.estey.com/
AOL IM: flufflegavin (Add Buddy, Send Message)

Hacker in NYC.

Journal of gav (2710)

Wednesday August 28, 2002
07:05 PM

quick hacks are us

[ #7376 ]
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 (<DATA>) {
    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 ..

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.

  •     my $i = 1;
        my %month = map { $_ => $i++ } qw/jan ... dec/;


    Hmmm. How about:


        my %month;
        @month{ qw/jan ... dec/ } = 1..12;


    And also:


        DOMAIN: while (<DATA>) {
            chomp;
            next if /^\s*$/;
            my @whois = `whois $_`;
            LINE: foreach my $line (@whois) {
                if ($line =~ /expire/i) {