tags:

views:

169

answers:

3

I tried the following command unsuccessfully

sdiff <(ping www.nato.int) <(ping www.reuters.com)

Is there any way to have a real-time comparison between ping times?

+1  A: 

How about:

watch 'ping -c 4 www.google.com; echo; ping -c 4 www.yahoo.com'

Gives result such as this:

Every 2.0s: ping -c 4 www.google.com; echo; ping -c 4 www.yahoo.com                                                                          Tue Apr  7 13:57:47 2009

PING www.l.google.com (74.125.39.105) 56(84) bytes of data.
64 bytes from fx-in-f105.google.com (74.125.39.105): icmp_seq=1 ttl=248 time=8.06 ms
64 bytes from fx-in-f105.google.com (74.125.39.105): icmp_seq=2 ttl=248 time=8.47 ms
64 bytes from fx-in-f105.google.com (74.125.39.105): icmp_seq=3 ttl=248 time=8.37 ms
64 bytes from fx-in-f105.google.com (74.125.39.105): icmp_seq=4 ttl=248 time=8.19 ms

--- www.l.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 8.061/8.276/8.478/0.196 ms

PING www-real.wa1.b.yahoo.com (87.248.113.14) 56(84) bytes of data.
64 bytes from f1.us.www.vip.ird.yahoo.com (87.248.113.14): icmp_seq=1 ttl=56 time=43.3 ms
64 bytes from f1.us.www.vip.ird.yahoo.com (87.248.113.14): icmp_seq=2 ttl=56 time=44.3 ms
64 bytes from f1.us.www.vip.ird.yahoo.com (87.248.113.14): icmp_seq=3 ttl=56 time=42.4 ms
64 bytes from f1.us.www.vip.ird.yahoo.com (87.248.113.14): icmp_seq=4 ttl=56 time=43.0 ms

--- www-real.wa1.b.yahoo.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 42.422/43.277/44.301/0.728 ms

Do you need to subtract the ping times? Does it have to be side by side (a bit annoying)? What's your ideal output format?

Jaka Jančar
@Jaka: Which shell do you use? I could not find the watch command in Linux repositories.
Masi
I use bash. watch is in package 'procps' on Debian (probably similar in Ubuntu). It's available as a seperate package ('watch') via Fink on Mac OS X.
Jaka Jančar
The command works fine also without echo;
Masi
I know, I just liked a bit of space in between :)
Jaka Jančar
+1  A: 

You could do this using say perl/python/php/otherlang and time how long it takes to open a connection to say port 80 for instance. You can store this into a variable and then use this for mathematical analysis.

Something like this in psuedo-code:

$site1_start = get_timestamp();
$sock = opensocket($someAddress,$required_port);
if($sock) { $sock->close(); };
$site1_end = get_timestamp();
$site1_round_trip = $t2 - $t1

$site2_start = get_timestamp();
$sock = opensocket($someAddress);
if($sock) { $sock->close(); };
$site2_end = get_timestamp();
$site2_round_trip = $t2 - $t1

// now we can perform some stuff on the round trips
Wayne
+1  A: 

Usually I just open two xterms side-by-side and run ping in each. Or in one terminal "ping host1 & ping host2&"

fping -e will give you the latency to a list of hosts in one run. So you can just do: watch fping -e www.google.com www.yahoo.com www.kernel.org

Not everyone has watch, but you can just do this (and then you can see the history): while :; do date; fping -e www.google.com www.yahoo.com www.kernel.org; sleep 1; done

The output is still ugly, and not everyone has fping installed either..

Here's a start if you want to produce decent looking output. Just give it a list of hosts as arguments.

#!/usr/bin/perl
use strict;
use warnings;
use POSIX;

for(;;) {
    print strftime("%T:", localtime);
    foreach my $host (@ARGV) {
        my $a=`ping -c 1 $host`;
        my $latency;
        if($a =~ /rtt.* =\s+([\d.]+)\//s) {
            $latency=$1;
        } else {
            $latency="(dropped)";
        }
        print "$host:$latency\t";
    }
    print "\n";
    sleep(1);
}
chuck
Thank you for your response! I accept the answer because it is most platform-independent.
Masi