Re: Advanced ping


#1

fr Peter:

I remember i did this long time ago in Python by calling the command

line ping and screen-scraping the result. Ugly solution, but worked.

same here, but i’ve always trusted the os-level ping,

so something like,

irb(main):009:0> p=ping 10.2.10.4 -c 5
=> “PING 10.2.10.4 (10.2.10.4) 56(84) bytes of data.\n64 bytes from
10.2.10.4: icmp_seq=1 ttl=255 time=0.635 ms\n64 bytes from 10.2.10.4:
icmp_seq=2 ttl=255 time=0.513 ms\n64 bytes from 10.2.10.4: icmp_seq=3
ttl=255 time=0.519 ms\n64 bytes from 10.2.10.4: icmp_seq=4 ttl=255
time=0.525 ms\n64 bytes from 10.2.10.4: icmp_seq=5 ttl=255 time=0.507
ms\n\n— 10.2.10.4 ping statistics —\n5 packets transmitted, 5
received, 0% packet loss, time 4000ms\nrtt min/avg/max/mdev =
0.507/0.539/0.635/0.056 ms\n”
irb(main):010:0> puts p
PING 10.2.10.4 (10.2.10.4) 56(84) bytes of data.
64 bytes from 10.2.10.4: icmp_seq=1 ttl=255 time=0.635 ms
64 bytes from 10.2.10.4: icmp_seq=2 ttl=255 time=0.513 ms
64 bytes from 10.2.10.4: icmp_seq=3 ttl=255 time=0.519 ms
64 bytes from 10.2.10.4: icmp_seq=4 ttl=255 time=0.525 ms
64 bytes from 10.2.10.4: icmp_seq=5 ttl=255 time=0.507 ms

— 10.2.10.4 ping statistics —
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.507/0.539/0.635/0.056 ms
=> nil

irb(main):029:0* tx,rx,loss,time=p.scan(/(\d+) packets transmitted,
(\d+) received, (\d+)% packet loss, time (\d+)ms/).flatten
=> [“5”, “5”, “0”, “4000”]
irb(main):030:0> tx
=> “5”
irb(main):032:0> rx
=> “5”
irb(main):033:0> loss
=> “0”
irb(main):034:0> time
=> “4000”
irb(main):036:0* min,avg,max,mdev=p.scan(/rtt min/avg/max/mdev =
(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+) ms/ ).flatten
=> [“0.507”, “0.539”, “0.635”, “0.056”]
irb(main):037:0> min
=> “0.507”
irb(main):038:0> avg
=> “0.539”
irb(main):039:0> max
=> “0.635”
irb(main):040:0> mdev
=> “0.056”

Anything better over here?

'm not sure either. but if it is wriiten in ruby, it should look better
:slight_smile:

kind regards -botp


#2

Peña wrote:

Anything better over here?

'm not sure either. but if it is wriiten in ruby, it should look better :slight_smile:
;-)) I am already rolling with Ruby, but I can not really remember
Python had String.scan()
which is actually a very nice method in Ruby.

Thx a lot!