Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Net::Whois::Raw silently fails

by neilwatson (Curate)
on Oct 31, 2006 at 14:29 UTC ( #581498=perlquestion: print w/ replies, xml ) Need Help??
neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

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

Comment on Net::Whois::Raw silently fails
Download Code
Re: Net::Whois::Raw silently fails
by Corion (Pope) on Oct 31, 2006 at 14:35 UTC

    I blame your uninformative error message:

    # 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; }

    Once you replace your "Whois failed" with something more informative, it should become much clearer where the error lies:

    $expires{$d} = "Whois failed for $d: Couldn't decipher '$who'" +;
      The error message did help. Thank you. I tried something similar but, the format for the printed report truncated the error message (my bad). Also, whois servers sometimes get upset by to many requests in a short period of time. I placed a sleep (10 seconds) in the domain loop and things are working now.

      Neil Watson
      watson-wilson.ca

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://581498]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-07-31 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (245 votes), past polls