#!/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 timeout] -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; };