Determining if a client PC has an Internet connection

Chris S. chrisks at NOSPAM.udel.edu
Sun Sep 19 19:38:34 EDT 2004


Cliff Wells wrote:

> 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?

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.



More information about the Python-list mailing list