in reply to ping count is automatically setting to 1
This is based on a combination of your code above, the code from 1050022 and some of my own.
#!/bin/env perl use strict; use warnings; use Getopt::Long; use Net::Ping; my $host; my $count = 5; my $interval = 1; my $packetsize = 64; # remember that header data will be added to this my $timeout = 5; # 5 is the default in Net::Ping GetOptions( "h|host=s", \$host, "c|count=i", \$count, "i|interval=i", \$interval, "s|packetsize=i", \$packetsize, "W|timeout=i", \$timeout, # you had w|allowableTime but t +his makes more sense to me ); die "$0: No host given!\n" unless ( defined $host ); my $p = Net::Ping->new( 'tcp', # BUG: Should be able to change this with a command line op +tion $timeout, $packetsize, ); $p->hires(); my %stats = ( received => 0, tsum => 0, max => 0, min => 9999999999 ); for ( 1 .. $count ) { my ( $ret, $duration, $ip ) = $p->ping( $host ); if ( $ret ) { $duration *= 1000; $stats{received}++; $stats{min} = $duration if ( $duration < $stats{min} ); $stats{max} = $duration if ( $duration > $stats{max} ); $stats{tsum} += $duration; printf "Your RTT is %.2f ms\n", $duration; } sleep $interval if ( defined $interval && $interval > 0 ); } if ( $stats{received} > 0 ) { $stats{avg} = $stats{tsum} / $stats{received}; } $stats{loss} = ( $count - $stats{received} ) / $count * 100; print "--- $host ping statistics ---\n"; printf "%d packets transmitted, %d received, %d%% packet loss\n", $cou +nt, $stats{received}, $stats{loss}; printf "rtt min/avg/max = %.2f/%.2f/%.2f ms\n", $stats{min}, $stats{av +g}, $stats{max} if $stats{received} > 0; __DATA__ [mmusgrove@nmsdev2 mm-nms_4.5 ~]$ ./ping.pl -h 10.130.25.2 --- 10.130.25.2 ping statistics --- 5 packets transmitted, 0 received, 100% packet loss [mmusgrove@nmsdev2 mm-nms_4.5 ~]$ ./ping.pl -h 10.130.25.1 -c 8 Your RTT is 0.50 ms Your RTT is 0.37 ms Your RTT is 0.34 ms Your RTT is 0.35 ms Your RTT is 0.37 ms Your RTT is 0.36 ms Your RTT is 0.41 ms Your RTT is 0.35 ms --- 10.130.25.1 ping statistics --- 8 packets transmitted, 8 received, 0% packet loss rtt min/avg/max = 0.34/0.38/0.50 ms
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: ping count is automatically setting to 1
by Anonymous Monk on Aug 26, 2013 at 19:30 UTC | |
|
Re^2: ping count is automatically setting to 1
by gaurav (Sexton) on Aug 24, 2013 at 06:50 UTC | |
by gaurav (Sexton) on Aug 24, 2013 at 06:58 UTC | |
by Mr. Muskrat (Canon) on Aug 26, 2013 at 18:22 UTC | |
by gaurav (Sexton) on Aug 27, 2013 at 03:43 UTC |