Best way to check if there is internet?

Cameron Simpson cs at cskk.id.au
Mon Feb 7 16:25:33 EST 2022


On 07Feb2022 11:40, Grant Edwards <grant.b.edwards at gmail.com> wrote:
>Ah, c'mon... Every geek worth his salt knows a few real world IP
>addresses without relying on DNS. If you want to "ping Google", it's
> $ ping 8.8.8.8
> $ ping 8.8.4.4

And Cloudflare is 1.1.1.1. Speaking as someone who's seen his upstream 
provider have good G connectivity and degraded C connectiviy :-(

>If that doesn't work, then you ask 'route -n' for the IP address of
>the default gateway,

I tend to just check for the presence of the default route for services 
which should be "up" when there's internet. (Persistent ssh tunnels, in 
the main.) Not even a ping.

Some of those tunnels are further conditioned on a specific ping.

"ping -c 5 -q ip-addr-here" can be a simple Boolean test.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list