Community discussions

MikroTik App
 
droux
just joined
Topic Author
Posts: 1
Joined: Tue Feb 08, 2022 12:09 pm

Detecting Internet connection

Tue Feb 08, 2022 12:31 pm

I am on routerOS 7.1.

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:

[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:

[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:

[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:

[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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Detecting Internet connection

Tue Feb 08, 2022 3:55 pm

Have you looked at the netwatch function?

https://www.youtube.com/watch?v=UgKfkhyynKk

Who is online

Users browsing this forum: No registered users and 24 guests