[4737] in RedHat Linux List
Re: whois
daemon@ATHENA.MIT.EDU (Arnt Gulbrandsen)
Sat Nov 16 21:51:18 1996
To: Robert Hart <iweft@ipax.com.au>
Cc: Red Hat <redhat-list@redhat.com>,
Red Hat Developers <redhat-devel-list@redhat.com>
From: Arnt Gulbrandsen <arnt@gulbrandsen.priv.no>
Date: 17 Nov 1996 03:47:18 +0100
In-Reply-To: Robert Hart's message of Sun, 17 Nov 1996 13:41:37 +1100 (EST)
Resent-From: redhat-list@redhat.com
Reply-To: redhat-list@redhat.com
Robert Hart <hartr@interweft.com.au>
> I have just discovered that Red Hat does not include a proper whois
> client. This is quite important when tracking down client DNS problems!
I append an evil hack you might stoop to using. It improves slightly
on the original whois by selecting one of three default servers
depending on search string.
--Arnt
#!/usr/bin/perl
use Socket;
require "/usr/lib/perl5/getopts.pl";
use FileHandle;
$host = "rs.internic.net";
$port = "whois";
&Getopts("h:");
$host = $opt_h if defined($opt_h);
die "usage: $0 [ -h host ] name\n" if ($#ARGV != 0);
$host = "whois.ripe.net" if ( $host eq "rs.internic.net" &&
$ARGV[0] =~ /\.[a-zA-Z][a-zA-Z]$/ );
$host = "nic.ddn.mil" if ( $host eq "rs.internic.net" &&
$ARGV[0] =~ /\.mil$/i );
$SOCKET = &connectServer($host,$port);
print $SOCKET "$ARGV[0]\n";
while (<$SOCKET>) {
print $_;
}
close($SOCKET);
sub connectServer {
local($host,$port) = @_;
local($name, $aliases,$proto,$thisaddr,$thataddr,$this,$that);
$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($host);
die "Unknown host \"$host\".\n" unless $thataddr;
$this = pack($sockaddr, &AF_INET, 0, $thisaddr);
$that = pack($sockaddr, &AF_INET, $port, $thataddr);
socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!\n";
bind(S, $this) || die "bind: $!\n";
connect(S, $that) || die "connect: $!\n";
socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!\n";
bind(S, $this) || die "bind: $!\n";
connect(S, $that) || die "connect: $!\n";
S->autoflush(1);
S
}
--
PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
________________________________________________________________________
http://www.redhat.com/RedHat-FAQ http://www.redhat.com/RedHat-Errata
http://www.redhat.com/RedHat-Tips http://www.redhat.com/mailing-lists
------------------------------------------------------------------------
To unsubscribe: mail -s unsubscribe redhat-list-request@redhat.com < /dev/null