#!/usr/local/bin/perl # # This script will ping a range of IP addresses given # a starting and ending address. There are other faster # ways to do this, for example, the nmap program, but this # is also an example on how to manipulate IP addresses in Perl. # # Andy Welter # www.the-welters.com # January 2001 # use Socket; $packet_count=1; $usage="ping_scan [ending ip address]\n"; ($#ARGV >= 0) || die "$usage"; $cur_str=$ARGV[0]; if ($#ARGV == 0 ) { $end_str=$cur_str; } else { $end_str=$ARGV[1]; }; # # Convert "1.2.3.4" notation address into an integer. $cur_bin= unpack "L", inet_aton $cur_str; $end_bin= unpack "L", inet_aton $end_str; while ( $cur_bin <= $end_bin ) { # # Convert integer into a 1.2.3.4 notation address. $cur_str=inet_ntoa (pack "L", $cur_bin); print "$cur_str ... "; # # Ping the host open (PING, "ping $cur_str $packet_count |") || die "Cannot execute ping command\n"; while ( $_ = ) { print $_; }; close PING; $cur_bin++; };