rbc has asked for the wisdom of the Perl Monks concerning the following question:
#!/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<<DOIT; $0 -N<network> [-p<protocal>][-S<start>][-E<end>][-T<timeout>][-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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Why does Net::Ping behave this way?
by Fletch (Bishop) on Apr 02, 2002 at 23:21 UTC | |
by rbc (Curate) on Apr 02, 2002 at 23:57 UTC | |
Re: Why does Net::Ping behave this way?
by gav^ (Curate) on Apr 02, 2002 at 23:39 UTC | |
(tye)Re: Why does Net::Ping behave this way?
by tye (Sage) on Apr 03, 2002 at 20:58 UTC | |
Re: Why does Net::Ping behave this way?
by brianarn (Chaplain) on Apr 03, 2002 at 19:37 UTC |