From: lindner@mudhoney (Paul Lindner)
Subject: Better Gopher->whois script available
Original-To: gopher-news@boombox.micro.umn.edu (Gopher News Mailing List)
Date: Tue, 21 Jul 92 20:29:55 CDT
Reply-To: lindner@boombox.micro.umn.edu.
X-Mailer: ELM [version 2.3 PL11]
Newsgroups: alt.gopher
Distribution: alt

As an example of what can be shoehorned into the old types I've
reimplemented Roland Schemers gophertowhois script, using direct
connections to whois servers, and also made it possible to service
multiple whois servers with one script.  I've also added parsing to
make more whois servers directly browsable.

The service has been installed on gopher.micro.umn.edu's Phone Books
directory.  Have a look.

One interesting consequence of sticking with Type=7 items is that we
can use a mindexd superserver to search a bunch of whois servers in
parallel.  This is tomorrows project :-)



Here's a simple readme file I cobbled together.
------------------------------------------------
In this distribution is a simple and relatively (ha!) readable Perl
script called gtowhois.  The script implements an internet Gopher to
WHOIS gateway.  Different whois servers are specified by links with
the Path set to "qwhois <hostname>"

The gopher client connects to the gtowhois server and sends a query to
it.  The server takes the query, sends it off to the whois server and
then parses the resulting output.  The script understands a few of the
more popular whois-gateways, including:

     X.500 whois gateway
     Ph whois gateway
     Weird Stanford Whois gateway
     Horton (coming soon....)

One item is always returned, the raw search results.  If the script
can parse the output of the search individual user entries are
presented.

The script is designed to be run by inetd as a TCP daemon.
The easiest way to explain how to set it up and how it works
is to use an example.

Let us assume that we want to run a gopher to FTP gateway on
a machine called hell.micro.umn.edu. 

1.  You need to have Perl available on the machine.  If you don't you
can ftp the sources from a variety of anonymous ftp sites including

	uunet.uu.net
	jpl-devvax.jpl.nasa.gov
	tut.cis.ohio-state.edu

2.  Edit the first few, (marked) lines of the gtowhois file for your
local configuration; in this case change the marked lines as follows:

#
# Administrator parameters
#
$Gatehost 	= "mudhoney.micro.umn.edu";
$Port		= 4324;


3.  Become root and place the gtowhois file someplace nice (like
/usr/local/bin or /usr/etc or wherever you place stuff like this);
assume we put it in /usr/local/bin.  Make it owned by root and
executable:

    chown root gtowhois
    chmod 755 gtowhois

4.  Update /etc/services by adding the following line to the
/etc/services file (note it's tab between gtowhois and 4324):

    gtowhois	4324/tcp

Nothing sacred about 4324.  Run it at 6666 if you like...
For SUNs running yp, you'll also want to do a make services:
    cd /var/yp
    make services

5. Now update /etc/inetd.conf (for BSD-ish systems) or
/etc/servers (on Ultrix or A/UX or others) depending on what you
have.
For /etc/inetd.conf, add a line:

gtowhois	stream	tcp	nowait	root	/usr/local/bin/gtowhois	gtowhois

For /etc/servers, add a line:

gtowhois	tcp	/usr/local/bin/gtowhois

Note tabs between fields.

6.  Kill and restart the inetd daemon whatever the prescribed way
to do that on your machine.

7.  You can confirm that gtowhois is running now at port 4324 by
telneting to hell.micro.umn.edu at port 4324. Type a hostname at 
it (eg: boombox.micro.umn.edu), and it should respond by returning
the anonymous ftp directories available at boombox.micro.umn.edu.

8.  Now make some links from a regular gopher server to the gtowhois
service.  On a unix server, the links could look like this (on a 
Mac server, do the functional equivalent using Gopher's Helper):

 Name=Worcester Polytechnic Institute
 Type=7
 Port=4324
 Path=qwhois wpi.wpi.edu
 Host=mudhoney.micro.umn.edu


Credit for the original idea goes to schemers@leland.Stanford.EDU
(Roland Schemers).

---gtowhois------------------snip------snip---------snip---------

#!/usr/local/bin/perl

#
# Administrator parameters
#
$Gatehost 	= "mudhoney.micro.umn.edu";
$Port		= 4324;


sub reply { print "$_[0]\r\n";}


sub OpenWHOIS { 
    local($them,$port,$query) = @_;
    $them = 'localhost' unless them;
    $port = 43 unless $port;

    $AF_INET = 2;
    $SOCK_STREAM = 1;

    $SIG{'INT'} = 'dokill';

    $sockaddr = 'S n a4 x8';

    chop($hostname = `hostname`);

    ($name,$aliases,$proto) = getprotobyname('tcp');
    ($name,$aliases,$port) = getservbyname($port,'tcp')
        unless $port =~ /^\d+$/;;
    ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
    ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);

    $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
    $that = pack($sockaddr, $AF_INET, $port, $thataddr);

    # Make the socket filehandle.
    socket(WHOIS, $AF_INET, $SOCK_STREAM, $proto) || die $!;

    # Give the socket an address.
    bind(WHOIS, $this) || die $!;

    # Call up the server.
    connect(WHOIS,$that) || die $!;

    # Set socket to be command buffered.
    select(WHOIS); $| = 1; select(STDOUT);

    # send the whois query
    print WHOIS "$query\r\n";
}



$_ = <STDIN>; s/\r//; s/\n//;

 #
 # This whois thingie doesn't support a blank thing
 #

 if (/^$/) {
    &reply("0Whois Help\twhois help\t$host\t$port");
    &reply("7Query Whois\tqwhois\t$host\t$port");
    &reply(".");
    exit(0);
 }

 #
 # a straight whois query, expect format of "whois <hostname> query..."
 #

  if (/^whois/) {
    /^whois ([^\s]*)\s(.*)/;
    $host  = $1;
    $query = $2;
    &OpenWHOIS($host,43,$query);
    while(<WHOIS>) {
        chop;
        &reply($_);
    }
    &reply(".");
    exit;
  }

  if (/^qwhois/) {
    /^qwhois (.*)\t(.*)/;
    $host  = $1;
    $query = $2;
    &OpenWHOIS($host,43,$query);
    
    while(<WHOIS>) {
        s/\n//;
        s/\r//;
        push(@lines,$_);
    }

    #
    # Always return the output of the whois search first
    #

    &reply("0Raw Search Results\twhois $host $query\t$Gatehost\t$Port");

    #
    # Test for some common formats
    #

    #
    # CSO gateway whois type servers
    #

    foreach (@lines) {
           if (/\s+name:\s+(.*)/) {
              $newquery = $1;
	      $newquery =~ s/,//g; #remove commas
              $newquery =~ s/\s+[A-z]$//; #remove trailing middle initial
	      &reply("0$1\twhois $host $newquery\t$Gatehost\t$Port");
           }
    }

    #
    # nic.ddn.mil type whois servers
    #

    foreach (@lines) {
	if (/(.*)\((.*)\)\t(.*)$/) {
		&reply("0$1\twhois $host !$2\t$Gatehost\t$Port");
        }
    }

    #
    # format used by stanford.edu
    #    
    if ($lines[$#lines] =~ /^\(returned/) {
       foreach (@lines) {
           if (/(.*)<(.*)>.*\s+(.*)$/) {
               $text=$1; $handle=$2; $rest = $3;
               $text =~ s/\s+$//;
               $rest =~ s/\s+/ /g;
               &reply("0$text ($rest)\twhois $host $handle\t$Gatehost\t$Port");
           }
        }
    }

    #
    # format used by X.500 gateways.
    #
    if ($lines[0] =~ m/[0-9]+ matches found/) {
        foreach (@lines) {
             if (/^\s+[0-9]+\.(.*)\s+   (.*)$/) {
                $newname = $1;
                $newname =~ s/^\s+//;
		$newname =~ s/\s+$//;
		&reply("0$newname ($2)\twhois $host $newname\t$Gatehost\t$Port");
             }
        }
    }

    #
    # format used by horton: username@host  Name  Date
    #

    foreach (@lines) {
        if (/([\S]+@[\S]+).*([A-z][A-z][A-z] [A-z][A-z][A-z]\d\d \d\d\d\d)[\s]+$/) {
		#Not implemented yet.
        }
    }


    if ($lines[$#lines] eq 'NO MATCH' ||
        $lines[$#lines] eq 'Unable to resolve name') {
       &reply("0No Match Was Found!\twhois $host help\t$Gatehost\t$Port");
       &reply(".");
       exit(0);
    }

    &reply(".");
    exit(0);

  }

exit;

---------.Links for whois servers
Type=7
Name=Bull HN Information Systems
Path=qwhois bull.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Cambridge Computer Associates
Path=qwhois camb.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=GTE Laboratories
Path=qwhois gte.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=InterCon Systems Corporation
Path=qwhois intercon.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Prime Computer
Path=qwhois relay.prime.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Performance Systems International
Path=qwhois wp.psi.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=SRI International
Path=qwhois sri.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Sunquest Information Systems
Path=qwhois whois.sunquest.com
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of California at Berkeley
Path=qwhois mailhost.berkeley.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=California Institute of Technology
Path=qwhois caltech.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=California Institute of Technology
Path=qwhois horton.caltech.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=California State University - Fresno
Path=qwhois csufres.csufresno.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=California State University - Hayward
Path=qwhois csuhayward.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=California State University - Sacramento
Path=qwhois csus.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Florida State University
Path=qwhois cc.fsu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Gettysburg College
Path=qwhois gettysburg.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=George Mason University
Path=qwhois gmu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Harvard University
Path=qwhois whois.harvard.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Indiana University
Path=qwhois indiana.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=USC Information Sciences Institute
Path=qwhois isi.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Johns Hopkins University
Path=qwhois jhunix.hcf.jhu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Merit Computer Network
Path=qwhois merit.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Miami, Rosentiel School of Marine and Atmospheric
Path=qwhois whois.rsmas.miami.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Massachusetts Institute of Technology
Path=qwhois mit.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Mississippi State University
Path=qwhois whois.msstate.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Northern Arizona University
Path=qwhois nau.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=North Carolina State University
Path=qwhois whois.ncsu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Notre Dame
Path=qwhois nd.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=New Jersey Institute of Technology
Path=qwhois earth.njit.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=New York University, Courant Institute
Path=qwhois acfcluster.nyu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=New York University
Path=qwhois wp.nyu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Ohio Northern University
Path=qwhois austin.onu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Oregon State University
Path=qwhois orst.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Ohio State University
Path=qwhois osu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Portland State University
Path=qwhois wp.pdx.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Rochester
Path=qwhois whois.cc.rochester.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Rutgers University
Path=qwhois whitepages.rutgers.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=San Diego State University
Path=qwhois sdsu.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Sonoma State University
Path=qwhois sonoma.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Stanford University
Path=qwhois stanford.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=State University of New York, Stony Brook
Path=qwhois sunysb.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Syracuse University
Path=qwhois syr.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Baylor College of Medicine
Path=qwhois whois.bcm.tmc.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Cincinnati
Path=qwhois uc.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of California at Davis
Path=qwhois directory.ucdavis.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Chicago
Path=qwhois uchicago.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of California at Los Angeles
Path=qwhois oac.ucla.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of California at San Diego
Path=qwhois ucsd.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Florida
Path=qwhois whois.eng.ufl.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Houston
Path=qwhois whois.uh.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Maryland
Path=qwhois umd5.umd.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Minnesota
Path=qwhois umn.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Nebraska at Lincoln
Path=qwhois unl.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Oregon
Path=qwhois oregon.uoregon.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Oregon
Path=qwhois whois.uoregon.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Pennsylvania
Path=qwhois whois.upenn.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Virginia
Path=qwhois whois.virginia.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Wisconsin
Path=qwhois wisc.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Worcester Polytechnic Institute
Path=qwhois wpi.wpi.edu
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Lawrence Berkeley Laboratory
Path=qwhois wp.lbl.gov
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Lawrence Livermore National Laboratory
Path=qwhois llnl.gov
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=NASA Ames Research Center
Path=qwhois orion.arc.nasa.gov
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=National Energy Research Supercomputer Center
Path=qwhois wp.nersc.gov
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=DDN Network Information Center
Path=qwhois nic.ddn.mil
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Naval Research Laboratory
Path=qwhois whois.nrl.navy.mil
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=MCNC - Center for Communications
Path=qwhois ncnoc.concert.net
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=EASInet Operations Center
Path=qwhois nis.easi.net
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Energy Sciences Network
Path=qwhois wp.es.net
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=New Jersey Intercampus Network
Path=qwhois njin.net
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Reseaux IP Europeens
Path=qwhois whois.ripe.net
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Wirtschaftsuniversitaet Wien
Path=qwhois whois.wu-wien.ac.at
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Adelaide
Path=qwhois wp.adelaide.edu.au
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Western Australia
Path=qwhois uwa.edu.au
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Saskatchewan
Path=qwhois whois.usask.ca
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Western Ontario
Path=qwhois whohost.uwo.ca
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Gesellschaft fuer Mathematik und Datenverarbeitung
Path=qwhois dfnnoc.gmd.de
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Dansk UNIX-system Bruger Gruppe
Path=qwhois dkuug.dk
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Helsinki University of Technology
Path=qwhois cs.hut.fi
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Tampere University of Technology
Path=qwhois tut.fi
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Institut National de Recherche en Informatique et Automatique
Path=qwhois inria.inria.fr
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Universite Claude Bernard Lyon I
Path=qwhois whois.univ-lyon1.fr
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=National Centre for Software Technology
Path=qwhois sangam.ernet.in
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Association of Research Networks in Iceland
Path=qwhois isgate.is
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=University of Canterbury
Path=qwhois cantsc.canterbury.ac.nz
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Victoria University, Wellington
Path=qwhois vuw.ac.nz
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Waikato University
Path=qwhois waikato.ac.nz
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Chalmers University of Technology
Path=qwhois chalmers.se
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Swedish Institute of Computer Science
Path=qwhois sics.se
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=SUNET (Swedish University Network)
Path=qwhois whois.sunet.se
Host=mudhoney.micro.umn.edu
Port=4324
#
Type=7
Name=Imperial College
Path=qwhois doc.ic.ac.uk
Host=mudhoney.micro.umn.edu
Port=4324
#



-- 
 | Paul Lindner | lindner@boombox.micro.umn.edu   | Slipping into madness
 |              | Computer & Information Services | is good for the sake
 | GopherMaster | University of Minnesota         | of comparision.
///// / / /    /////// / / / /  /  /  /   /      //// / / / /  /  /  /   /