Yuck, please don't use goto. Perl has next and last, which means you nearly never need the evil goto. Also, you could have saved a couple temporary variables in various places; f.ex $RAW = join "", <DATA>; would have let you get away without @INFO. (Even better would have been to write $RAW = do { local $/; <DATA> }; .) print ".."; exit; is nearly always better written as die "..";.

Update { I forgot to mention: you should really check out Mark-Jason Dominus' excellent Program Repair Shop and Red Flags article series on Perl.com }

That said, I would have used Net::Ping (as already suggested), and I'd also use one of the Getopt::* modules to make the script more flexible. Here's one possible rendition:

#!/usr/bin/perl -w use strict; use Net::Ping 2.13; # earlier versions do not return ping time use Getopt::Std; my %opt = ( i => 1, m => 65536, p => "udp", r => 20, t => 1, ); getopts("a:i:m:p:t:r:", \%opt) and $opt{a} or die << "USAGE"; usage: $0 -a addr [-i minsize] [-m maxsize] [-p proto] [-r retr] [-t t +imeout] -a destination address -i initial ping size in bytes [default: 1] -m max ping size in bytes [default: 63536] -p protocol: tcp, udp, icmp [default: udp] -r maximum nr. or retries [default: 20] -t timeout in seconds [default: 1] USAGE my ($addr, $bytes, $maxsize, $proto, $timeout, $retries) = @opt{qw(a i m p t r)}; $Net::Ping::max_datasize = 65536; # we want to send huge packets until($bytes > $maxsize) { my $p = Net::Ping->new($proto, $timeout, $bytes); $p->hires(1); # precise ping times my ($success, $time); my $retry = 0; ($success, $time) = $p->ping($addr) until $success or (++$retry > $retries); die "Sorry, host $addr not found or network problem.\n" if not defined $success; die "Host $addr seems to have died at $bytes bytes packet size.\n" if $success == 0; printf "%3.2f msec for $bytes bytes packet size", $time; print " (traffic hiccuped, $retry tries)" if $retry > 1; print "\n"; ++$bytes; };
Update: now tested. I also just noticed that the documentation of Net::Ping says you can only set the data size to 1024 bytes at most. There's a constant for that limit in the module however; I added a line to remove that limit.

Makeshifts last the longest.


In reply to Re: Ping Stress Test by Aristotle
in thread Ping Stress Test by foxops

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.