Question: How do I check for an active Internet connection, if I cannot do UDP, and /ping has no useful return code?
This is proving way harder than I would have expected. The /ping command does not have an exit code that I can check (!)
First, following https://help.mikrotik.com/docs/display/ ... t+Internet cannot work. Because UDP is blocked by my provider, so it never switches from wan to internet:
Code: Select all
[admin@MikroTik] /interface/detect-internet/state> print
Columns: NAME, STATE, STATE-CHANGE-TIME
# NAME STATE STATE-CHANGE-TIME
0 wlan1 no-link feb/07/2022 13:23:20
1 lte1 wan feb/07/2022 13:23:26
Next I tried /ping.
And /ping gives me different results from what these forums tell me I should expect. Maybe a v7+ issue? This is what I see:
For a valid IP:
Code: Select all
[admin@MikroTik] > :set $pingResult [:ping count=1 1.1.1.1]
Columns: SEQ, HOST, SIZE, TTL, TIME
SEQ HOST SIZE TTL TIME
0 1.1.1.1 56 51 118ms503us
[admin@MikroTik] > :put [:typeof $pingResult ]
nothing
For an invalid IP:
Code: Select all
[admin@MikroTik] > :set $pingResult [/ping count=1 172.1.1.1]
Columns: SEQ, HOST, STATUS
SEQ HOST STATUS
0 172.1.1.1 timeout
[admin@MikroTik] > :put [:typeof $pingResult ]
nothing
... which means there is no way for me to check the exit code of the /ping command?
This is what I am seeing because of that, and it blows my mind:
Code: Select all
[admin@MikroTik] > :if ([/ping 1.1.1.1 count=1] = 1) do={:put "Down"} else={:put "Up"}
Columns: SEQ, HOST, SIZE, TTL, TIME
SEQ HOST SIZE TTL TIME
0 1.1.1.1 56 51 134ms149us
Up
[admin@MikroTik] > :if ([/ping 172.1.1.1 count=1] = 1) do={:put "Down"} else={:put "Up"}
Columns: SEQ, HOST, STATUS
SEQ HOST STATUS
0 172.1.1.1 timeout
Up