I wrote this script to report domain expiries. Net::Whois::Raw seems to fail silently (returns 'Whois failed') more often than it succeeds. A standard UNIX whois always works. What could the problem be?
#!/usr/bin/perl use strict; use warnings; # Fix Redhat issues with UTF8 $ENV{LC_ALL} = 'en_US'; use Net::Whois::Raw; use Date::Manip qw(ParseDate UnixDate DateCalc Delta_Format); # Report domain only if days left is less than # a given argument. Default is 60. my $left; if (defined $ARGV[0]){ $left = $ARGV[0]; }else{ $left = 60; } # Add or subtract domains to check from here. my @domains = qw( example.ca example.net example.org ); my ($d, $who, $domain, $expire, %expires, $days, $edate); format STDOUT_TOP= Domains that expire in less than @<<< days $left Domain Expires Days Left ------------------------------------------------------ . format STDOUT= @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<< @### $domain, $expire, $days . # Calculate days to expiration. foreach $d (@domains){ # Lookup domain with whois $who = whois($d) or die "Cannot reach whois server"; # Get expiration date if ($who =~ m/expir.*?(\d{2}-\w{3}-\d{4})/i) { $edate = $1; }elsif ($who =~ m|renewal-date.*?(\d{4}/\d{2}/\d{2})|i) { $edate = $1; }else{ $expires{$d} = "Whois failed"; next; } # Parse expiration date to yyyy/mm/dd. $expires{$d} = dateparse($edate); } # Generate report foreach $d (sort keys %expires){ $domain = $d; $expire = $expires{$d}; # Do not calculate expired dates if whois failed if ($expire eq 'Whois failed') { $days = 0; }else{ $days = daystoexpire($expires{$d}); } # Only report if expiration date is earlier than stated. if ($days <= $left){ write STDOUT; } } # Parse date to yyyy/mm/dd sub dateparse { my $datestr = shift; my ($y, $m, $d) = UnixDate($datestr, "%Y", "%m", "%d"); my $date = "$y/$m/$d"; return $date; } # Calculate days until domain expires sub daystoexpire { my $date = shift; my $days = DateCalc("today", $date); # Format delta date to days. $days = Delta_Format($days, 2, '%dh'); return $days; }

Neil Watson
watson-wilson.ca


In reply to Net::Whois::Raw silently fails by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.