in reply to Re: ping count is automatically setting to 1
in thread ping count is automatically setting to 1

And also RTT MDEV

  • Comment on Re^2: ping count is automatically setting to 1

Replies are listed 'Best First'.
Re^3: ping count is automatically setting to 1
by gaurav (Sexton) on Aug 24, 2013 at 06:58 UTC

    Thanks for it,what about TTL value and RTT mdev

      I'll give you RTT mdev*. BTW, I've also changed the output to show 3 decimal places.

      #!/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, tsum2 => 0, max => 0, min => 9 +999999999 ); 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; $stats{tsum2} += $duration * $duration; printf "Your RTT is %.3f ms\n", $duration; } sleep $interval if ( defined $interval && $interval > 0 ); } if ( $stats{received} > 0 ) { $stats{avg} = $stats{tsum} / $stats{received}; $stats{avg2} = $stats{tsum2} / $stats{received}; $stats{mdev} = sqrt( $stats{avg2} - $stats{avg} * $stats{avg} ); } $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/mdev = %.3f/%.3f/%.3f/%.3f ms\n", $stats{min}, + $stats{avg}, $stats{max}, $stats{mdev} if $stats{received} > 0;

      Update: I'm not giving you TTL because Net::Ping does not provide that information. Stick to what you are using if you really need this info.

      * Source: http://serverfault.com/a/333203/67820

        Thank you very much