in reply to Re: Re: Ping and Tracert
in thread Ping and Tracert

Run ping, generate some output and then I will suggest a regex for you to capture the max. This runs under Win32. The output is after the __DATA__ - you can see the output of ping which puts the regex into perspective.

$ip = 'www.perlmonks.com'; $ping = `ping $ip`; @times = $ping =~ m/time=(\d+)ms/g; @times = sort { $b <=> $a } @times; print "High to low @times ms\n"; print "Highest $times[0] ms\n"; print "Lowest $times[-1] ms\n"; print "This was the repy parsed\n$ping\n"; __DATA__ High to low 414 413 408 403 ms Highest 414 ms Lowest 403 ms This was the repy parsed Pinging www.perlmonks.com [206.170.14.76] with 32 bytes of data: Reply from 206.170.14.76: bytes=32 time=408ms TTL=237 Reply from 206.170.14.76: bytes=32 time=413ms TTL=237 Reply from 206.170.14.76: bytes=32 time=414ms TTL=237 Reply from 206.170.14.76: bytes=32 time=403ms TTL=237

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Re: Re: Ping and Tracert
by qball (Beadle) on Aug 31, 2001 at 23:56 UTC
    Hey, I'm getting blanks for my times. I'm running the same script, but receiving the following output:
    High to low ms Highest ms Lowest ms

    Thanks.

    qball~"I have node idea?!"

      What text does ping return? On Win32 it returns blah blah blah time=123ms so we match on the "time=123ms" bit. If the ping output format is different (as it will be on *nix) you just need to modify the regex. Post some sample ping output as captured by this sort of call (or whatever you are using) $ping = `ping`; print $ping and it will be easy to munge the times out of the return strings.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        This is running on Linux.
        $ip = 'www.perlmonks.org'; $ping = `ping -c 3 $ip`; @times = $ping =~ /time=(\d+\.\d+)/; @times = sort { $b <=> $a } @times; print "High to low @times ms\n"; print "Highest $times[0] ms\n"; print "Lowest $times[-1] ms\n"; print "This was the reply parsed\n$ping\n";
        And here are the results.
        High to low 87.719 ms Highest 87.719 ms Lowest 87.719 ms This was the reply parsed PING www.perlmonks.org (206.170.14.76) from 207.16.70.63 : 56(84) byte +s of data. 64 bytes from yoda.blockstackers.com (206.170.14.76): icmp_seq=0 ttl=2 +38 time=87.719 msec 64 bytes from yoda.blockstackers.com (206.170.14.76): icmp_seq=1 ttl=2 +38 time=81.823 msec 64 bytes from yoda.blockstackers.com (206.170.14.76): icmp_seq=2 ttl=2 +38 time=82.001 msec --- www.perlmonks.org ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max/mdev = 81.823/83.847/87.719/2.758 ms
        It's not giving me the right data in the highest, lowest and highest to lowest. Please help.

        Thanks

        qball~"I have node idea?!"