#!/bin/perl #Output the IP address and fully qualified domain name of every host #on the same network as the given host. #The first argument is the hostname or IP address of a given host, #e.g., i5.nyu.edu or 128.122.253.142 #The second argument is the number of network bits in the netmask, e.g., 26 use Socket; if (@ARGV != 2) { die "$0: requires 2 arguments"; } $begin = $ARGV[0]; $end = $ARGV[1]; #number of network bits in the bitmask $ipbegin = inet_aton($begin) or die "$0: argument $hostname must be a hostname or dotted IP address"; $ipend = inet_aton($end) or die "$0: argument $hostname must be a hostname or dotted IP address"; $ibegin = unpack('N', $ipbegin); $iend = unpack('N', $ipend); for ($i = $ibegin + 1; $i <= $iend; ++$i) { $ip = pack('N', $i); $name = gethostbyaddr($ip, AF_INET); if (defined $name) { print inet_ntoa($ip), ' ', $name, "\n"; } } exit 0;