Ping response parse depending on RouterOS version using API

I wanted to know if someone has an example of parsing output of ping when trying to do it with a lot of hosts, depending on the version mikrotika. Or maybe somebody can give a pice of advice…I’ve spend a lot of time tring to find a solution

I’m not sure why you have to write parser specifically for ping. You just have to write generic parser for parameters, and use it for ping like for any other command.

Possible received parameters in v5 are:

!re
=host=y.y.y.y
=status=timeout
=sent=1
=received=0
=packet-loss=100

!re
=host=x.x.x.x
=size=56
=ttl=64
=time=00:00:00
=sent=11
=received=11
=packet-loss=0
=min-rtt=00:00:00
=avg-rtt=00:00:00
=max-rtt=00:00:00.001

The point is that if we want to ping several hosts using tag command in RouterOS v5 then after receiving !done from any ping tagged command parses decides that the whole ping command is finished. As an example debuging information using RouterOS < 5

<<< [5] /ping
<<< [20] =address=xx.xx.xx.xx
<<< [8] =count=5
<<< [14] =interval=20ms
<<< [6] =ttl=8
<<< [6] .tag=1
<<< [5] /ping
<<< [22] =address=xx.xx.xx.xx
<<< [8] =count=5
<<< [14] =interval=20ms
<<< [6] =ttl=8
<<< [8] =size=28
<<< [6] .tag=2

[5/5 bytes read.
[5, 36] !done
[6/6 bytes read.
[6, 29] =ret=0
[6/6 bytes read.
[6, 22] .tag=1
[5/5 bytes read.
[5, 15] !done
[6/6 bytes read.
[6, 8] =ret=5
[6/6 bytes read.
[6, 1] .tag=2
Nice. We’ve send ping command to 2 host with two tags and as an output we’ve received 2 !done’s and ping result.
Example of debuging info using
RouterOS 5
<<< [5] /ping
<<< [20] =address=xx.xx.xx.xx
<<< [8] =count=5
<<< [14] =interval=20ms
<<< [6] =ttl=8
<<< [8] =size=28
<<< [6] .tag=1
<<< [5] /ping
<<< [22] =address=xx.xx.xx.xx
<<< [8] =count=5
<<< [14] =interval=20ms
<<< [6] =ttl=8
<<< [8] =size=28
<<< [6] .tag=2
[3/3 bytes read.
[3, 385] !re
[19/19 bytes read.
[19, 365] =host=xx.xx.xx.xx
[8/8 bytes read.
[8, 356] =size=28
[7/7 bytes read.
[7, 348] =ttl=62
[14/14 bytes read.
[14, 333] =time=00:00:00
[7/7 bytes read.
[7, 325] =sent=1
[11/11 bytes read.
[11, 313] =received=1
[14/14 bytes read.
[14, 298] =packet-loss=0
[17/17 bytes read.
[17, 280] =min-rtt=00:00:00
[17/17 bytes read.
[17, 262] =avg-rtt=00:00:00
[17/17 bytes read.
[17, 244] =max-rtt=00:00:00
[6/6 bytes read.
[6, 237] .tag=2
[3/3 bytes read.
[3, 232] !re
[17/17 bytes read.
[17, 214] =host=xx.xx.xx.xx
[15/15 bytes read.
[15, 198] =status=timeout
[7/7 bytes read.
[7, 190] =sent=1
[11/11 bytes read.
[11, 178] =received=0
[16/16 bytes read.
[16, 161] =packet-loss=100
[6/6 bytes read.
[6, 154] .tag=1
[3/3 bytes read.
[3, 149] !re
[19/19 bytes read.
[19, 129] =host=xx.xx.xx.xx
[8/8 bytes read.
[8, 120] =size=28
[7/7 bytes read.
[7, 112] =ttl=62
[14/14 bytes read.
[14, 97] =time=00:00:00
[7/7 bytes read.
[7, 89] =sent=2
[11/11 bytes read.
[11, 77] =received=2
[14/14 bytes read.
[14, 62] =packet-loss=0
[17/17 bytes read.
[17, 44] =min-rtt=00:00:00
[17/17 bytes read.
[17, 26] =avg-rtt=00:00:00
[17/17 bytes read.
[17, 8] =max-rtt=00:00:00
[6/6 bytes read.
[6, 1] .tag=2
[3/3 bytes read.
[3, 232] !re
[17/17 bytes read.
[17, 214] =host=xx.xx.xx.xx
[15/15 bytes read.
[15, 198] =status=timeout
[7/7 bytes read.
[7, 190] =sent=2
[11/11 bytes read.
[11, 178] =received=0
[16/16 bytes read.
[16, 161] =packet-loss=100
[6/6 bytes read.
[6, 154] .tag=1
[3/3 bytes read.
[3, 149] !re
[19/19 bytes read.
[19, 129] =host=xx.xx.xx.xx
[8/8 bytes read.
[8, 120] =size=28
[7/7 bytes read.
[7, 112] =ttl=62
[14/14 bytes read.
[14, 97] =time=00:00:00
[7/7 bytes read.
[7, 89] =sent=3
[11/11 bytes read.
[11, 77] =received=3
[14/14 bytes read.
[14, 62] =packet-loss=0
[17/17 bytes read.
[17, 44] =min-rtt=00:00:00
[17/17 bytes read.
[17, 26] =avg-rtt=00:00:00
[17/17 bytes read.
[17, 8] =max-rtt=00:00:00
[6/6 bytes read.
[6, 1] .tag=2
[3/3 bytes read.
[3, 232] !re
[17/17 bytes read.
[17, 214] =host=xx.xx.xx.xx
[15/15 bytes read.
[15, 198] =status=timeout
[7/7 bytes read.
[7, 190] =sent=3
[11/11 bytes read.
[11, 178] =received=0
[16/16 bytes read.
[16, 161] =packet-loss=100
[6/6 bytes read.
[6, 154] .tag=1
[3/3 bytes read.
[3, 149] !re
[19/19 bytes read.
[19, 129] =host=xx.xx.xx.xx
[8/8 bytes read.
[8, 120] =size=28
[7/7 bytes read.
[7, 112] =ttl=62
[14/14 bytes read.
[14, 97] =time=00:00:00
[7/7 bytes read.
[7, 89] =sent=4
[11/11 bytes read.
[11, 77] =received=4
[14/14 bytes read.
[14, 62] =packet-loss=0
[17/17 bytes read.
[17, 44] =min-rtt=00:00:00
[17/17 bytes read.
[17, 26] =avg-rtt=00:00:00
[17/17 bytes read.
[17, 8] =max-rtt=00:00:00
[6/6 bytes read.
[6, 1] .tag=2
[3/3 bytes read.
[3, 246] !re
[17/17 bytes read.
[17, 228] =host=xx.xx.xx.xx
[15/15 bytes read.
[15, 212] =status=timeout
[7/7 bytes read.
[7, 204] =sent=4
[11/11 bytes read.
[11, 192] =received=0
[16/16 bytes read.
[16, 175] =packet-loss=100
[6/6 bytes read.
[6, 168] .tag=1
[3/3 bytes read.
[3, 163] !re
[19/19 bytes read.
[19, 143] =host=xx.xx.xx.xx
[8/8 bytes read.
[8, 134] =size=28
[7/7 bytes read.
[7, 126] =ttl=62
[14/14 bytes read.
[14, 111] =time=00:00:00
[7/7 bytes read.
[7, 103] =sent=5
[11/11 bytes read.
[11, 91] =received=5
[14/14 bytes read.
[14, 76] =packet-loss=0
[17/17 bytes read.
[17, 58] =min-rtt=00:00:00
[17/17 bytes read.
[17, 40] =avg-rtt=00:00:00
[17/17 bytes read.
[17, 22] =max-rtt=00:00:00
[6/6 bytes read.
[6, 15] .tag=2
[5/5 bytes read.
[5, 8] !done
[6/6 bytes read.
[6, 1] .tag=2
Why reading stoped without receiving !done from the .tag=1 ?

this should be problem with client implementation you are using. it seems it is not made with concurrent commands in mind.

Client should handle this correctly, to not to stop upon !done, when there is more commands coming in.