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


In reply to Re: ping count is automatically setting to 1 by Mr. Muskrat
in thread ping count is automatically setting to 1 by gaurav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.