#!/usr/bin/perl -w # FindHosts.pl by Adam Rogoyski (apoc@laker.net) # Copyright (C) 1997 Adam Rogoyski # usage: ./findhosts.pl ip # ex: bash-2.00$ ./findhosts.pl 205.245.74. # --- GNU General Public License Disclamer --- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. use strict; my ($baseip, $name, $aliases, $type, $length, $ip, $i, @addresses); $baseip = shift || die "usage: ./findhosts.pl xxx.xxx.xxx."; if ($baseip !~ /^\d+\.\d+\.\d+\.$/) { print STDERR "usage: ./findhosts.pl xxx.xxx.xxx.\n"; print STDERR "ex : ./findhosts.pl 205.245.74.\n"; exit 1; } $name = $aliases = $type = $length = 0; @addresses = (); for ($i = 1; $i <= 255; $i++) { $ip = $baseip . $i; ($name, $aliases, $type, $length, @addresses) = gethostbyaddr(pack('C4', split('\.', $ip)), 2); if ($addresses[0]) { printf "$ip $name\n"; } else { print "$ip \n"; } }