home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / GOPHER / GO4GW1.2B / G2WHOIS < prev    next >
Encoding:
Text File  |  1993-04-29  |  4.7 KB  |  185 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #----------------------------------------------------------------------
  4. # variables you should change:
  5.  
  6. $whois_server = "umn.edu";   
  7. $whois_port   = 43;
  8.  
  9. #----------------------------------------------------------------------
  10.  
  11. sub whois_main {
  12.     local($_) = @_;
  13.     
  14.     if (/^$/) {
  15.     &Greply("0Search Instructions\thelp\t$whois_server\t$whois_port");
  16.     &Greply("7Query Whois server $whois_server\t$Ggw $whois_server\t$Ghost\t$Gport");
  17.     &Greply(".");
  18.     exit(0);
  19.     }
  20.     
  21.     ($whois_server, $query) = split('\t');
  22.     
  23.     &GopenServer($whois_server,$whois_port);
  24.     &Gsend($query);
  25.     
  26.     while(<GSERVER>) {
  27.     s/\n//;
  28.     s/\r//;
  29.         push(@lines,$_);
  30.     }
  31.     
  32.     #
  33.     # Always return the output of the whois search first
  34.     #
  35.     
  36.     &Greply("0Raw search results\t$query\t$whois_server\t$whois_port");
  37.     
  38.     
  39.     #
  40.     # Test for some common formats
  41.     #
  42.     
  43.     #
  44.     # CSO gateway whois type servers
  45.     #
  46.     
  47.     foreach (@lines) {
  48.     if (/\s+name:\s+(.*)/ ||
  49.         /\s+person:\s+(.*)/) {
  50.         $newquery = $1;
  51.         $newquery =~ s/,//g; #remove commas
  52.         $newquery =~ s/\s+[A-z]$//; #remove trailing middle initial
  53.         &Greply("0$1\t$newquery\t$whois_server\t$whois_port");
  54.     }
  55.     }
  56.     
  57.     #    
  58.     # nic.ddn.mil type whois servers
  59.     #
  60.     
  61.     foreach (@lines) {
  62.     if (/(.*)\((.*)\)\t(.*)$/) {
  63.         &Greply("0$1\t!$2\t$whois_server\t$whois_port");
  64.     }
  65.     }
  66.     
  67.     #
  68.     # format used by stanford.edu
  69.     #    
  70.     if ($lines[$#lines] =~ /^\(returned/) {
  71.     foreach (@lines) {
  72.         if (/(.*)<(.*)>.*\s+(.*)$/) {
  73.         $text=$1; $handle=$2; $rest = $3;
  74.         $text =~ s/\s+$//;
  75.         $rest =~ s/\s+/ /g;
  76.         &Greply("0$text ($rest)\t$handle\t$whois_server\t$whois_port");
  77.         }
  78.         }
  79.     }
  80.  
  81.  
  82.  
  83.      #
  84.      # Format used at whohost.uwo.ca Try to handle both long form and short
  85.      # forms.  Long is a series of <field-name>: <field-value> pairs
  86.      # Short format: two lines with name on first and department indented
  87.      # on the second.
  88.  
  89.      if ($lines[0] =~ /^There were [0-9]+ matches on your request\./ ||
  90.        $lines[0] =~ /^\s+Full\sName: .*$/) {
  91.        foreach (@lines) {
  92.          if (/:/) {  # must be full form
  93.            if (/^\s+Full\sName: (.*)$/) {      #the name field
  94.                $fullname = $1;
  95.            }
  96.            if (/^\s+Department: (.*)$/) {      # department name
  97.                $department = $1;
  98.            }
  99.            if (/^\s+Index Key: (.*)$/) {       # index number
  100.                $newquery = $1;
  101.                &Greply("0$fullname  [$department]\tkey$newquery\t$whois_server\t$whois_port");
  102.            }
  103.          }
  104.          else { #short form (first line begins with <space> or *
  105.            if (/^[ *]([A-z0-9].*)\[(.*)\]/) {
  106.                $newquery = $2;              #grab index
  107.                $fullname= $1;               # and the name for display
  108.            }
  109.            if (/^  (.*)     /) {     # on the second line
  110.                $department = $1;            #get department
  111.                $department =~ s/ +$//;  #delete trailing spaces
  112.                &Greply("0$fullname  [$department]\tkey$newquery\t$whois_server\t$whois_port");
  113.            }
  114.          }
  115.        }
  116.     }
  117.  
  118.     
  119.     #
  120.     # format used by X.500 gateways.
  121.     #
  122.     if ($lines[0] =~ m/[0-9]+ matches found/) {
  123.         foreach (@lines) {
  124.         if (/^\s+[0-9]+\.(.*)\s+   (.*)$/) {
  125.                 $newname = $1;
  126.                 $newname =~ s/^\s+//;
  127.         $newname =~ s/\s+$//;
  128.         &Greply("0$newname ($2)\t$newname\t$whois_server\twhois_port");
  129.         }
  130.         }
  131.     }
  132.     
  133.     #
  134.     # Format used by sunysb.edu, software unknown.
  135.     #
  136.     if ($lines[0] =~ /^Connection received/) {
  137.     foreach (@lines) {
  138.         if (/^(.*)MailName:/) {
  139.         &Greply("0$1\t$1\t$whois_server\twhois_port");
  140.         }
  141.         }
  142.     }
  143.     
  144.     #
  145.     # format used by horton: username@host  Name  Date
  146.     #
  147.     
  148.     foreach (@lines) {
  149.         if (/([\S]+@[\S]+).*([A-z][A-z][A-z] [A-z][A-z][A-z]\d\d \d\d\d\d)[\s]+$/) {
  150.         #Not implemented yet.
  151.         }
  152.     }
  153.     
  154.     
  155.     
  156.     foreach (@lines) {
  157.     if (/^\s+name:\s+(.*)/) {
  158.         &Greply("0$1\t$query\t$whois_server\t$whois_port");
  159.         &Greply(".");
  160.         exit(0);
  161.     }
  162.     }
  163.  
  164.     if ($lines[$#lines] eq 'NO MATCH') {
  165.     &Greply("0No Match Was Found!\thelp\t$gopher_server\t$gopher_port");
  166.     } elsif ($lines[$#lines] =~ /^\(returned/) {
  167.     foreach (@lines) {
  168.         if (/(.*)<(.*)>.*\s+(.*)$/) {
  169.         $text=$1; $handle=$2; $rest = $3;
  170.         $text =~ s/\s+$//;
  171.         $rest =~ s/\s+/ /g;
  172.         &Greply("0$text ($rest)\t!$handle\t$whois_server\t$whois_port");
  173.         }
  174.     }
  175.     }
  176.     
  177.     &Greply(".");
  178.     exit(0);
  179. }
  180.  
  181.  
  182.  
  183.  
  184. 1; # for require
  185.