home *** CD-ROM | disk | FTP | other *** search
- eval 'exec perl -s -S $0 ${1+"$@"}'
- if 0;
-
- #-------
- # nslook.pl - simple name server lookup
- #
- # Usage:
- # nslook [-l] [hostname|IP address] ...\n";
- #
- # Options:
- # -l long format output
- #
- # Idea from a program of the same name posted in alt.sources
- # by Juergen Nickelsen <nickel@cs.tu-berlin.de>, 10 Sep 91.
- #
- # DaviD W. Sanderson
- #-------
-
- # require 'sys/socket.ph'; # use this if you have to...
- sub AF_INET {2;}
-
- #-------
- # These convert between the decimal quartet and the internal form of
- # the internet addresses.
- #-------
- sub inet2str
- {
- sprintf('%u.%u.%u.%u', unpack('C4', $_[0]));
- }
- sub str2inet
- {
- $_[0] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
- pack('C4', $1, $2, $3, $4);
- }
-
- #-------
- # Return a description of the results of a gethost* function.
- #-------
- sub HostDesc
- {
- local ($name, $aliases, $addrtype, $length, @addrs) = @_;
- local ($desc);
-
- $desc .= 'Name: '. $name. "\n" if $name ne '';
- $desc .= 'Alias: '. $aliases. "\n" if $aliases ne '';
-
- foreach (@addrs)
- {
- $desc .= 'Address: '. &inet2str($_). "\n";
- }
-
- $desc;
- }
-
- #-------
- # Look up the address or hostname in $_.
- #-------
- sub DoArg
- {
- local(@ans);
- local($ans);
-
- if(/^\d+\.\d+\.\d+\.\d+$/)
- {
- @ans = gethostbyaddr(&str2inet($_), &AF_INET);
- die "$0: $_: unknown address\n" if !defined @ans;
- $ans = $ans[0];
- }
- else
- {
- @ans = gethostbyname($_);
- die "$0: $_: unknown name\n" if !defined @ans;
- $ans = &inet2str($ans[4]);
- }
- $ans .= "\n";
- $ans = &HostDesc(@ans) if $l ne '';
- $ans;
- }
-
- $0 =~ s#.*/##;
-
- if ($#ARGV < $[)
- {
- print "usage: $0 [-l] [hostname|IP address] ...\n";
- exit 0;
- }
-
- for (@ARGV)
- {
- print &DoArg;
- }
-