Link to home
Start Free TrialLog in
Avatar of blenkhn
blenkhn

asked on

multiple whois queries

I would like to build a program which will be able to ask internic for a whois then ask the autoritive registrar's whois server for information and loop it 50 times (max).  I have been using a command line program which works very well except for the occasional "Can't print to server" error.  I hve three questions:
1.  Is there a way to keep a channel open for multiple queries?
2.  How does one keep the program working after such an error?
3.  Using the following script how does one change the whois server dynamically?

my $out=whois($host);

print $out;

sub whois {
   my $sock = IO::Socket::INET->new(
   PeerAddr => ($_[1]?$_[1]:'whois.publicinterestregistry.net'),
   PeerPort => 'whois(43)',
   Proto    => 'tcp',
   Timeout  => 60) or die "IO::Socket::INET: $!";

   $sock->print($_[0],"\r\n");
   my @result=$sock->getlines;
   $sock->close;
   return wantarray?@result:join('',@result);
}

Thanks for your help.
Avatar of Tintin
Tintin

1. No, the WHOIS protocol doesn't have this possibility.

2. Automatic retry:

my $out;
for (1..10)
{
   eval
   {
      $out = whois($host);
   };

   last unless $@;  # stop trying if successful

   sleep(1);        # wait 1 seconds before next try
}

if (defined $out)
{
   print $out;
}
else
{
   print STDERR "Could not retrieve domain information";
}

3. Do you mean this:

out = whois($host, "whois.something.net");
Avatar of blenkhn

ASKER

Thanks for your reply,

With using the statement

out = whois($host, "whois.something.net");

do I still need to have the statement

 PeerAddr => ($_[1]?$_[1]:'whois.publicinterestregistry.net').

How do I change the script to do this?

You don't need to change anything - either you set the whois server explicitly when calling the whois() function or it uses the default server (whois.publicinterestregistry.net).
Avatar of blenkhn

ASKER

Thanks for your reply,

With using the statement

out = whois($host, "whois.something.net");

do I still need to have the statement

 PeerAddr => ($_[1]?$_[1]:'whois.publicinterestregistry.net').

How do I change the script to do this?

ASKER CERTIFIED SOLUTION
Avatar of Trevize
Trevize

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blenkhn

ASKER

I have used your suggestion to cancel out the errors occuring from the whois server.  what about transmission errors?  maybe a timer to rehit the server after so long? How would one check to see if the complete record has been received?