#!/usr/bin/perl -w use strict; use Net::Ping; use Getopt::Std; my $protocal = "icmp"; my $network = "user must enter"; my $start = 0; my $end = 255; my $timeOut = 1; use vars qw/ $opt_p $opt_N $opt_S $opt_E $opt_T $opt_h/; getopt( "p:N:S:E:T:h" ); if( $opt_p ) {$protocal = $opt_p;} if( $opt_N ) {$network = $opt_N} else { &usage(); exit(); } if( $opt_S ) {$start = $opt_S} if( $opt_E ) {$end = $opt_E} if( $opt_T ) {$timeOut = $opt_T} if( $opt_h ) {&useage(); exit();} my $p = Net::Ping->new($protocal,$timeOut); for(my $node=$start; $node<$end; $node++){ my $address = "$network.$node"; print $address,($p->ping($address) ? ' is alive' : ' is not alive'),"\n"; } $p->close(); sub usage { print< [-p][-S][-E][-T][-h] network actually first 3 octects of an IP address protocal can be icmp, tcp or udp default is icmp start default 0 end default 255 timeout default 1 DOIT } #### $ ./ping.pl -N 123.321.12 -ptcp 123.321.12.0 is not alive 123.321.12.1 is not alive ^C // script seemed to hang $ ./ping.pl -N 123.321.12 -pudp 123.321.12.0 is not alive 123.321.12.1 is not alive 123.321.12.2 is not alive 123.321.12.3 is not alive 123.321.12.4 is not alive 123.321.12.5 is not alive 123.321.12.6 is not alive 123.321.12.7 is not alive ... 123.321.12.254 is not alive $ ./ping.pl -N 123.321.12 icmp ping requires root privilege at ./ping.pl line 21