Linux: created script for testing Internet connection

Hi all,

I’ve created a little Python 3 script that checks various connection settings for whenever my internet connection goes down. This still happens relatively often, either because I kicked out my cable, because Ubuntu managed to unload / deconfigure my network interface after sleep, because my home router is unavailable or stuck or finally because the link or PPPoE / IP layer is gone.

I wonder if somebody is interested in it to either test drive or to help develop:

Teaser:

[  OK  ] Ethernet connected
[  OK  ] Ethernet up
[  OK  ] Ethernet is default
[  OK  ] Gateway configured
[  OK  ] Gateway correct
[  OK  ] Linked to DSLAM
[  OK  ] Connected to ISP
[  OK  ] Freedom DNS pingable (185.93.175.43)
[  OK  ] Could reach https://www.freedom.nl
[  OK  ] Could reach https://www.google.com
[  OK  ] Could reach https://crypto.stackexchange.com

Of course, it might just run OK in the Linux subsystem for Windows as well.

Let me know if you want it and I’ll create a GitHub repo for it.

UPDATES:

  • 'm currently expanding on how I can best test DNS and line quality. For the first I need to intelligently test which DNS is used. Let me know if you find this useful!

  • For getting the line noise & attenuation I need the Fritz password. Does anybody think that testing for noise is the smart thing to do? And if that’s the case, is it worth the security risk of having to provide a password?

4 likes

I like your idea. I made something similar when i frequently needed to test internet connections for work.

I do have some suggestions:

  • Please use more privacy friendly checks then google and stackexchange
  • You could query the (freedom) DNS, verify the answer with a known answer and report the time it took to get it and the correctness of the answer
  • You could ping something and report the round trip time (RTT) and packet loss
  • You could try both http and https. Because a https session starts with exchange of keys/certificates it may run into MTU issues where http doesn’t, so the difference between them might be useful info when troubleshooting.

Personally i wouldn’t go as far as querying the fritzbox or make it optional. Such a check would bind it to users of fritzbox’s and your script could be quite generic without it.

1 like

Hi pa4wdh

Thanks for the feedback!
Here’s a point-to-point response.

  • The sites to check are of course meant to be configurable. Those are just important to me.
  • The DNS check was a ping and I agree that this was suboptimal. I now perform DNS queries instead, both to the modem / router and the DNS of Freedom.nl
  • I’ve removed the ping, but I might return it to check for packet loss.
  • Interesting point about the MTU, although I haven’t seen that particular issue pop up yet.

I was thinking about making the fritzbox optional. Another idea is to allow for a plugin structure so that it is easy to use a different script. To my surprise the web-API of Fritz is actually somewhat standardized it seems, as it uses the TR-064 protocol, so it might actually work on other modems (although I won’t hold my breath regarding that).

One of the main reasons that there is no internet connection is either line problems or the ISP not being available, so personally the script is a bit lost without that part; I need to know if I should contact KPN or Freedom (especially in the weekend when obviously Freedom cannot be reached anyway).

Cheers!

PS everything still in flux:

[  OK  ] Ethernet connected
[  OK  ] Ethernet up
[  OK  ] Ethernet is default
[  OK  ] Gateway configured
[  OK  ] Gateway correct
[  OK  ] Connected to DSLAM (down: 205.2 MBit/s, up: 59.4 MBit/s)
[  OK  ] Connected to ISP (IPv4: --- xxx ---, uptime: 127:36:17)
[  OK  ] Connected to ISP IPv6 (IPv6: --- xxx ---, validity: 4532:43:59)
[  OK  ] Router DNS servers available ['192.168.178.1'] (resolved: ['google.com'])
[  OK  ] ISP DNS servers available ['185.93.175.43', '185.232.98.76'] (resolved: ['www.freedom.nl', 'www.google.com', 'crypto.stackexchange.com'])
[  OK  ] Could reach https://www.freedom.nl/
[  OK  ] Could reach https://www.google.com/
[  OK  ] Could reach https://crypto.stackexchange.com/
[  OK  ] ISP IPv6 DNS servers available ['2a10:3780:2:52:185:93:175:43', '2a10:3780:2:53:185:232:98:76'] (resolved: ['ipv6.l.google.com'])
[  OK  ] Could reach https://ipv6.google.com

Nice progress!

Great idea, this is what i did in my (bash based) testing script. too. Make your tests as generic (and configurable) as possible to have maximum flexibility.

other solution:
at the point that you find the line is not working ‘fine’ and perhaps noise is the problem, let the program warn a human being
In that case you can check the info in the Fritz manually.
So you do not have to provide the password in any text-field.

1 like