Smart Methods for Linux Embedded Device to Detect Internet Connection

Our team is developing an internet media device based on Linux 2.6. We are currently detecting if an internet connection is established (via wired Ethernet i / f) by typing www.google.com

Some of the networks we tested the device on do not support ICMP forwarding, so our application code will erroneously report it to the Internet as unavailable in this case.

Does anyone know a finer approach to inferring whether an internet connection is available via / dev / eth 0 without having to check a known service?

+2


source to share


2 answers


As the guy who wrote this answer that ChristopheD refers to, this is not the approach I would use here. He worked on another question because in this case we were checking for a direct PPP link from the current computer - in this case you are connected to some network that may or may not have a default route, regardless of its wider connection to The Internet.

Since your application requires a global DNS connection, I would do that - find an address that you know will always exist, like a type query NS

for a domain com.

. Use a long enough timeout and / or try a few times before giving up. Something like that:



dig NS +aaonly com.

      

Ignore the output and check the exit value - 0 indicates that the search was able to reach the root servers, something else, and it was not.

+4


source


Ultimately, you want the device to be able to use the Internet for some useful function. If there is a well defined server that the device usually connects to, then it would be useful to send a request to it.

There are many steps in between "nothing" and "useful function", and you could test any of them as some measure of "connection":

  • Ethernet cable is connected (or PPP or Wi-Fi link is set, whichever is your low).
  • Assigned DHCP address (if applicable)
  • Default gateway active
  • DNS server responds
  • The destination server is responding (it may not be an ICMP ping, but a small HTTP request or any other protocol you could use)


Depending on how smart you are, or if you need a useful bug / diagnostic that they can report to tech support, it might be helpful to spot all of these.

It may also be useful to be able to use traceroute as a diagnostic tool.

+2


source







All Articles