#!/usr/bin/perl # Provided by Mike Beresford # Predeclare variables my $count = 0; my $predict = 0; my $diff = 0.0; my $real; # Infinite loop of pinging while(1) { # Read in hostname to ping $host = $ARGV[0]; # Ping, count=1 the host and parse out the reply string $real = `ping -c 1 $host | grep time=`; # Replace all the junk we don't want with nothing $real =~ s/.*ttl=[0-9]* time=//; $real =~ s/ ms\n//; # Find difference between predicted and actual values $diff = $predict - $real; # Print out vital info printf("(%d) real: %.3f\tpredicted: %.3f\t\tdiff: %.3f\n", $count, $real, $predict, $diff); $predict = $real; $count++; # Prevent ping floods sleep(1); }