Determining if a client PC has an Internet connection

Cliff Wells clifford.wells at
Sun Sep 19 12:20:56 CEST 2004

On Sun, 2004-09-19 at 09:03 +0000, Chris S. wrote:

> As others have mentioned, there's no clean-cut paradigm in the language 
> that can distinguish between the Internet and your local LAN. Your best 
> bet is to simple go about your business can try accessing hosts like 
> normal. When several of your requests timeout, then you can safely 
> assume the local host to be offline. That's what you see in those 
> applications when they say you're "offline"; an educated guess. After 
> all, if you can't reach your target, then you are, for all intents and 
> purposes, offline.

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?


Cliff Wells <clifford.wells at>

More information about the Python-list mailing list