#!/usr/bin/env perl # # whohas - whois, recurring upwards until it succeeds # # $Id$ sub die_unless_found { foreach my $x (@_) { grep { -x "$_/$x" } split /:/, $ENV{PATH} or die "fatal error: cannot find the required command: $x\n"; } } my $domain = pop(@ARGV) or die "supply a domain name as argument\n"; my $rest = join( ' ', @ARGV ); die_unless_found('whois'); while ( my $out = `whois $rest $domain` ) { if ( $out =~ /(^|[\r\n])\s*Domain.*:/i ) { # whois succeeded; succeed print $out; exit(0); } if ( !( $domain =~ s#^[^.]+\.## ) ) { # can't shorten the domain name; fail print $out; exit(1); } warn "trying $domain\n"; sleep(2) # whois.domain-registry.nl: maximum number of requests per second exceeded }