Best way to check if there is internet?

Chris Angelico rosuav at gmail.com
Mon Feb 7 07:59:04 EST 2022


On Mon, 7 Feb 2022 at 23:48, Lars Liedtke <liedtke at punkt.de> wrote:
>
> Each Browser is doing it differently and even Windows or
> Linux-Desktopmanagers (NetworkManager).
>
> I have had cases, where one tool told me I had Internet and another one
> I hadn't.

Not at all surprised :) Though that situation would probably be best
described as "degraded service". (Unless one tool was straight-up
misconfigured, of course.)

> So What Chris Angelico wrote is propably the best way, ping e.g. Google,
> do a DNS lookup and try http for Status 200. Each with its own
> Errorhandling and if you have got all three, then it is propable that
> you have "Internet".
>

More specifically, what I'm saying is that the best way to determine
whether you "have internet" is to do the exact thing that you care
about. What do you need the internet for? Downloading things from web
sites? Then attempt an HTTP request. Do you need UDP transmission?
Then send a UDP packet somewhere and wait for a response. Etc.

ChrisA


More information about the Python-list mailing list