A very basic attempt to gauge latency between two hosts using Net::Ping and Time::HiRes.
I'm not all that confident of its accuracy. Although, it seems to report timings fairly similar to my Linux ping utility. I created this for testing, I ended up using something like it in a module.
#!/usr/bin/perl
use warnings;
use strict;
use Net::Ping;
use Time::HiRes qw(tv_interval gettimeofday);
$|++;
my($host) = shift() || die("Usage: $0 <host.somewhere.com>\n");
my($ping) = Net::Ping->new('icmp');
while (1) {
my($timeStart) = [gettimeofday()];
if ($ping->ping($host, 2)) {
my($timeElapsed) = tv_interval($timeStart, [gettimeofday()]);
printf("%s: %.3f msec\n", $host, $timeElapsed * 1000);
} else {
my($timeElapsed) = tv_interval($timeStart, [gettimeofday()]);
printf("%s failed: %.3f\n", $host, $timeElapsed * 1000);
}
sleep(1);
}
$ping->close();
exit();