Best way to check if there is internet?
Lars Liedtke
liedtke at punkt.de
Mon Feb 7 07:47:14 EST 2022
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.
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".
Cheers
Lars
Am 07.02.22 um 10:33 schrieb Abdur-Rahmaan Janhangeer:
> Popular browsers tell: No internet connection detected. A function that
> goes in the same sense. Unless they too are pinging Google.com to check ...
>
> Kind Regards,
>
> Abdur-Rahmaan Janhangeer
> about <https://compileralchemy.github.io/> | blog
> <https://www.pythonkitchen.com>
> github <https://github.com/Abdur-RahmaanJ>
> Mauritius
>
>
> On Mon, Feb 7, 2022 at 1:28 PM Chris Angelico <rosuav at gmail.com> wrote:
>
>> On Mon, 7 Feb 2022 at 20:18, Abdur-Rahmaan Janhangeer
>> <arj.python at gmail.com> wrote:
>>> Greetings,
>>>
>>> Using the standard library or 3rd party libraries, what's the
>>> best way to check if there is internet? Checking if google.com
>>> is reachable is good but I wonder if there is a more native,
>>> protocol-oriented
>>> way of knowing?
>>>
>> What do you mean by "if there is internet"? How low a level of
>> connection do you want to test? You could ping an IP address that you
>> know and can guarantee will respond. You could attempt a DNS lookup.
>> You could try an HTTP request. Each one can fail in different ways,
>> for different reasons. It's best to test what you actually care about.
>>
>>> Even this URL recommends checking if a domain is up as a way to check for
>>> internet connectivity:
>>>
>> https://www.ibm.com/support/pages/checking-network-connectivity-when-using-python-and-ibm-resilient-circuits
>>
>> That talks about a misconfigured proxy as being the most likely cause.
>> Is that something you're trying to test for?
>>
>> There is no single concept of "there is internet". (Other than, in a
>> trivial sense, that the internet does exist.) What you need to know is
>> "can I use the internet?", and ultimately, that depends on what you
>> need it to do.
>>
>> ChrisA
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
--
punkt.de GmbH
Lars Liedtke
.infrastructure
Kaiserallee 13a
76133 Karlsruhe
Tel. +49 721 9109 500
https://infrastructure.punkt.de
info at punkt.de
AG Mannheim 108285
Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein
More information about the Python-list
mailing list