Determining if a client PC has an Internet connection

Jarek Zgoda jzgoda at gazeta.usun.pl
Sun Sep 19 04:14:12 EDT 2004


Cliff Wells <clifford.wells at comcast.net> pisze:

> I'm writing an application that needs to know if an Internet connection
> is available.  Basically, I want to have something similar to what a lot
> of email clients have, where the app can work either in "online" or
> "offline" mode (it keeps a cache of downloaded info, so it can work
> without a connection if needed).
> 
> The basic problem is this: it downloads info (RSS feeds) from a variety
> of sources.  Any one (or more) of these could conceivably fail to
> download, so simply waiting for a timeout isn't sufficient (not easy to
> differentiate between having a bad server and the client not having a
> connection).  Further, if it waits (say 30s) for the timeout to occur,
> this is going to be a bit annoying to the user.
> 
> I've considered trying to connect to a stable host (i.e. Google) and if
> that fails then assume the client can't connect to the internet, but
> this seems like a sub-optimal solution.
> 
> Is there any way to reliably determine the state of the client's
> internet connectivity?

No, there's no such way. You can try to connect to some "usually
working & available" host, but there always may be some periods, when
this host is not available (scheduled downtime, power outage, you name
it). The hosts known for its greatest stability are root DNS servers.

-- 
Jarek Zgoda
http://jpa.berlios.de/



More information about the Python-list mailing list