Determining if a client PC has an Internet connection

Cliff Wells clifford.wells at
Mon Sep 20 01:58:51 CEST 2004

On Sun, 2004-09-19 at 23:38 +0000, Chris S. wrote:
> Cliff Wells wrote:
> > 
> > Okay, at this point I suppose the better question would be how to make
> > an "educated guess".  As I mentioned, I've considered trying to open a
> > socket to one or more relatively stable hosts (i.e. Google, Yahoo, etc)
> > and if this fails, assume there is no Internet link.  However, this
> > clearly has it's flaws (those services, as unlikely as it seems, could
> > potentially be down, or they might be blocked by a corporate firewall,
> > etc).  Further, tying the application to an outside source that is, for
> > all intents, unrelated to the app seems a bit flaky.
>  >
> > Anyway, it occurs to me that a better "guess" might consist of whether
> > or not the app can reach the PC's primary/secondary DNS servers.  If
> > these are unreachable then it's a fair assumption that we aren't going
> > to get anywhere anyhow.  
> > 
> > So... is there a way of determining the DNS search path of a PC?
> My solution was far more mundane. I meant simply try and access the 
> internet the way you normally would. If it's a mail client, try and 
> access your users POP server. If it's a web-browser, try and retrieve a 
> web page the user wants. If you can't access them, then there's 
> essentially no "internet connection". In other words, don't worry about 
> whether or not there's an available connection. Instead, assume there is 
> a connection and worry about the status of your requests on the network.

Well, this is the fundamental problem.  It's an RSS aggregator, so there
is no single server it will be connecting to.  Further, because servers
can be added by the user or simply "disappear" because some blogger
decides he doesn't want to maintain a feed anymore, getting connection
errors will probably be quite common.  

Additionally, because I'm using Twisted, fetching the sites is
asynchronous, so I'm updating the cache and determining error messages
long before I have a chance to determine that all of the connections are
failing.  By the time I have that information, the damage has been done,
so to speak.

Given this situation, and the fact that there are specific requirements
(mentioned elsewhere) leaves me little choice but to use some guesswork
to determine whether or not a connection is present *prior* to fetching

Anyway, at this point I'm using the rather lame "check if both google
and yahoo are unavailable" method.  I'll find something better when I
have more time to devote to it.  I may use the effbot's suggestion for
Windows (InternetCheckConnection) and some other method for Linux and


Cliff Wells <clifford.wells at>

More information about the Python-list mailing list