#!/usr/bin/perl # RADB Query code # need this to allow access to sockets use Socket; sub ParseUrlEncoded; $whoishost = "whois.radb.net"; $port =43; $result = $ENV{QUERY_STRING}; # get the "searchst=" $SOCKADDR_IN = "S n A4 x8"; $PF_INET = 2; $SOCK_STREAM = 2; # first two lines important for CGI print "Content-type: text\/html\n"; print "\n"; { # convert each word. Change + to space and % to character foreach $word (split (/\&/, $result)) { ($label, $val) = split(/=/, $word); $val = ParseUrlEncoded($val); } # print the HTML header print "RADB Search Form\n"; print ""; print "

IRRWeb SearchForm

\n"; print "Search results for ", $val, ":\n
";

    # initialize the socket
    ($name, $aliases, $proto) = getprotobyname("tcp"); 
    socket(S, $PF_INET, $SOCK_STREAM, $proto) || die "socket failed: $!\n"; 

    # line buffered server
    select(S); $| = 1; select(STDOUT);
    ($name, $aliases, $type, $len, $thataddr) = gethostbyname($whoishost);
    $that = pack($SOCKADDR_IN, AF_INET, $port, $thataddr);
    connect(S, $that) || die "Connect failed\n";
    
    # send the request
    print S $val, "\n";
    print S "\n";
    
    # print response, each line seperated by 
while ($line = ) { print $line; print "
"; } # close the socket and print the rest of HTML close(S); print "

"; print "
"; print "Merit Network"; print " 4251 Plymouth Road Suite C Ann Arbor, MI 48105-2785"; print "
734-764-9430
info\@merit.edu"; print "
1999 Merit Network, Inc.
"; print "www\@merit.edu
"; print ""; } sub ParseUrlEncoded { my ($value) = @_; # replace '+' with ' ' $value =~ s/\+/ /g; # replace stuff like '%21' with '!' $value =~ s/%(..)/pack("c", hex($1))/ge; return $value; }