Unable to compare ping times on fly

前端 未结 3 1133
不知归路
不知归路 2021-01-28 00:22

I tried the following command unsuccessfully

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

Is there any way to have a real-t

相关标签:
3条回答
  • 2021-01-28 00:58

    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?

    0 讨论(0)
  • 2021-01-28 01:07

    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
    
    0 讨论(0)
  • 2021-01-28 01:17

    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);
    }
    
    0 讨论(0)
提交回复
热议问题