yup. attached (I didn't write it, William E. Weinman did)

works fine though.

On Tue, 8 Feb 2000, Nate Waddoups wrote:
> 
> Speaking of which, does anyone know of a command-line tool that will let
> you do:
> 
> $ whobe anyrandomdomain.com
> 
> ...and give you the results like whois when netsol had everything
> monopolized?  It'd kind of tedious to do whois in two steps and before I
> write a perl script to automate the process I figure I should ask if it's
> already been done.

hth
charles
#!/usr/bin/perl -w
#
# BW whois
#
# Copyright (c) 1999 William E. Weinman
# http://bw.org/
#
# Designed to work with the new-mangled whois system introduced 1 Dec 1999.
#
# Under the new domain-name regime the whois system is now distributed 
# amongst the various domain-police^H^H^H^H^H^H^H^H^H^H registrars, thereby

# requiring that we make at least two separate requests (to two separate 
# servers) for each whois record. 
#
# This program will first go to the "root" whois server and ask for a record. 
# If found, the root server will tell us where to go get the actual record, and 
# then we go get it. 
#
# Additional feature: If this program gets back a list of references instead 
# of a single record (as in the case of a record with a domain name for an 
# organization name), it will go out one more time and fetch the actual 
# record using the bang-handle. This became necessary because the "root" 
# whois server doesn't know where to tell you to go for a handle. Messy. 
#
# This program is free software. You may modify and distribute it under 
# the same terms as perl itself. 
#
# version 1.0 -- wew 2 Dec 1999  -- first release
# version 1.1 -- wew 3 Dec 1999 
#                   added --stripheader (by popular demand)
#                     thanks to Bill Shupp <[EMAIL PROTECTED]> for the concept.
#                   also -- now prints "Registrar: <host>" line (unless quiet)
# version 1.2 -- wew 3 Dec 1999
#                   added new syntax for specifying a host. can now say:
#                        whois <request>@<host>   as a synonym for: 
#                        whois -h <host> <request>
#                     thanks to Rob Friedman <[EMAIL PROTECTED]> for suggesting
#                     this feature. 
# version 1.3 -- wew 5 Dec 1999 
#                   added check for IP numbers or 'NETBLK' and set default to ARIN
#                     thanks to "Todd R. Eigenschink" <[EMAIL PROTECTED]>
#                   fixed an "uninitialized variable" problem. 
#                     thanks again to "Todd R. Eigenschink" <[EMAIL PROTECTED]>
# version 1.4 -- wew 8 Dec 1999 
#                   a hack for a mis-feature in the root whois server 
#                   at whois.internic.net. it seems to have a small number 
#                   of records that are not 2nd-level domains but are named

#                   the same as existing 2nd-level domains. I added a test 
#                   for a valid 2nd-level domain in whois_fetch() and have it 
#                   request the record as a domain. 
#                     thanks to Rick Macdougall <[EMAIL PROTECTED]>
# version 1.4a -- wew 8 Dec 1999 
#                   whois.corenic.net doesn't undderstand the domain command
#                   -- I guess the concept of standardization is lost on 
#                   these folks. Anyway, now I only send the domain command

#                   to whois.internic.net. 
#                     thanks to Cooper Vertz <[EMAIL PROTECTED]> for 
#                     pointing this out. 
#

use strict;
use vars qw( $host $quiet $stripheader ); 
use IO::Socket;
use Getopt::Long;

$host = '';
$quiet = '';
$stripheader = '';

my $banner  = "whois 1.4a by Bill Weinman <http://bw.org/>\n";
my $banner2 = "works with the new-mangled whois system introduced 1 Dec 1999\n"; 

use constant TRUE      => 1;
use constant FALSE     => '';

my $internic     = 'whois.internic.net';
my $default_host = $internic;               # starting point
my $netblk_host  = 'whois.arin.net';        # default host for netblocks
my $portname = 'whois(43)';
my $protoname = 'tcp';

# the text to test against for the end of a header with -s
my $headerstop = q{you agree to abide by this policy};
my $headerhost = 'networksolutions.com';  # host that uses these headers

GetOptions(
             "host=s" => \$host, 
             "stripheader!" => \$stripheader,
             "quiet!" => \$quiet 
           ) or usage();

my $domain = shift or usage();

# support for the <request>@<domain> syntax ...
unless ($host) { ($domain, $host) = split /\@/, $domain; }

# is it a netnum or NETBLK? try ARIN first
# $default_host = 'whois.arin.net' if $domain =~ /^[0-9\.]+$/ or $domain =~ 
/^!?NETBLK-/i;
$default_host = $netblk_host if $domain =~ /^([0-9\.]+$|!?NETBLK-)/i;

my @rc = ();
my $subrec = '';

# signon
print $banner unless $quiet;

# first: Go Fishin' at the InterNIC ... 
unless($host) {
  @rc = whois_fetch($default_host, $domain);
  grep { /Whois Server:\s*(.*)/i and $host = $1 } @rc;
  }

# now we know where to look -- let's go get it
if($host) {
  @rc = whois_fetch($host, $domain);
  grep {/\((.*-DOM)\).*$domain$/i and $subrec = $1 } @rc;
  }

# do we have a sub rec? If so, "Fetch!"
if($subrec) {
  print "found a reference to $subrec ... requesting full record ...\n" unless $quiet;
  @rc = whois_fetch($host, $subrec);
  }

# tell 'em what we found ...
print "Registrar: $host\n" if (@rc && $host && !$quiet);
my $headerflag = ($stripheader && $host && $host =~ /${headerhost}$/) ? TRUE : FALSE;
while(@rc) {
  my $l = shift @rc;
  print $l unless $stripheader && $headerflag;
  if($stripheader) {
    $headerflag = FALSE if($l =~ /$headerstop/i);
    }
  }

sub whois_fetch
{
my $host = shift;
my $domain = shift;
my @rc;

my $rs = IO::Socket::INET->new(
    PeerAddr  => $host,
    PeerPort  => $portname,
    Proto     => $protoname
  ) or die "$host not found\n";
my $IP = $rs->peerhost; 
print "connecting to $host [$IP] ... \n" unless $quiet;
$rs->autoflush(1);

# if it's a valid 2nd-level domain name, treat it as one. 
if($domain =~ /^[a-z\d\-]+\.[a-z\d\-]+$/ and $host eq $internic) { 
  $rs->print("domain $domain\r\n"); 
  }
else { $rs->print("$domain\r\n"); }
while(<$rs>) { 
  push @rc, $_;
  }
return @rc;
}

sub usage
{
print $banner, $banner2;
print <<USAGE;

usage: whois [options] <request>
   or: whois [options] <request>@<host>

options: 

  --host <host>  Hostname of the whois server
  -h <host>      this is the same as the <request>@<host> form
                 if not specified will search $default_host
                 for a "Whois Server:" record

  --quiet        Don't print any extraneous messages. 
  -q             ... "just the facts, ma'am"

  --stripheader  Strip off that silly disclaimer from the 
  -s             whois.networksolutions.com server. You've 
                 read it a thousand times already, right?

USAGE
exit;
}



Reply via email to