Best way to check if there is internet?

Abdur-Rahmaan Janhangeer arj.python at gmail.com
Mon Feb 7 04:33:54 EST 2022


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
>


More information about the Python-list mailing list