home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- setnetent(1);
- sethostent(1);
-
- for $host (@ARGV) {
- $name = '';
- if (@addrs = $host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
- @addrs = pack(C4, @addrs);
- ($name, $aliases, $addrtype, $length, @addrs) = gethostbyaddr($addrs[0],2);
- } elsif ($host =~ /^[\dx]+$/ ) {
- @addrs = pack(L, /^0/ ? oct : $_);
- ($name, $aliases, $addrtype, $length, @addrs) = gethostbyaddr($addrs[0],2);
- } else {
- ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host);
- # print " $host is really $name\n" if $host ne $name;
- }
- if (!$name) {
- warn "$0: gethostbysomething: $host: $!\n";
- next;
- }
- for $addr ( @addrs ) {
- @bytes = unpack(C4, $addr);
- $dotaddr = join('.', @bytes);
- printf "%-20s %-16s ",$name, "[$dotaddr]";
- $network = pack(C4, @bytes[0..2], 0); # XXX: apparent class C only
- ($name, $aliases, $addrtype, $net) = getnetbyaddr(unpack(L, $network),2);
- print $name ? $name : "an unnamed network";
- print " ($aliases)" if $aliases;
- print "\n";
- }
- }
-