OpenWrt Forum Archive

Topic: [HELP]Lua/Luci: How to check if the router has internet connectivity?

The content of this topic has been archived on 15 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I am really new developing for OpenWrt and was looking for it for a long time.
Sorry for my bad English, I am from Brazil.

I am using Lua and Luci to develop a OpenWrt interface.

I want to check if the router has internet connectivity. It could be making a HTTP GET request to my server or getting the IP address or in a simplest way.
I would appreciate not having to install external APIs. There is a way to do that?

Thank you in advance.

Melanke

You can do a ping command in the Network / Diagnostics.
If the router has internet it will get response like this:

PING openwrt.org (78.24.191.177): 56 data bytes
64 bytes from 78.24.191.177: seq=0 ttl=50 time=113.567 ms
64 bytes from 78.24.191.177: seq=1 ttl=50 time=113.169 ms
64 bytes from 78.24.191.177: seq=2 ttl=50 time=112.902 ms
64 bytes from 78.24.191.177: seq=3 ttl=50 time=112.913 ms
64 bytes from 78.24.191.177: seq=4 ttl=50 time=115.161 ms

--- openwrt.org ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 112.902/113.542/115.161 ms

I don't know if this may help you, but maybe you could parse that output.

The discussion might have continued from here.