Measuring Internet connection time

Dave Brueck dave at pythonapocrypha.com
Tue Mar 4 20:48:26 CET 2003


On Tue, 4 Mar 2003, No Spam wrote:

> Is there an easy way using Python to check if the computer (Windows XP) is
> connected to the Internet?
> I've tested a few programs I've found at download.com, but they either
> assume that I connect through a phone, which I don't, or they complain about
> som file,
> usually some .dll.
>
> I appreciate help since it will also help me learn more about Python.

Unfortunately this is way more problematic than it should be.  The best
hope I have found so far is to use the RAS APIs. Microsoft has provided
the Internet* APIs, but I have found them to be unreliable (often getting
false results in either direction).

I have a small RAS module for doing this, but it belongs to my employer;
I'll see if I can release it. In reality you need to figure out the proper
way to do this using the Microsoft APIs (in C) and then transliterate them
into Python using ctypes or your own Python extension module.

Also, you need to decide what you mean by "connected" - to know if you're
truly connected to the 'net in the sense of being able to connect to a
specific computer, the only sure-fire way to do that is to connect to that
computer! Having a LAN configured, or your modem dialed, doesn't guarantee
anything of course. You can simply try to connect to some well-known host
like google.com, but if the Windows user has a modem configured to
autodial then doing so will cause the modem to dial up their ISP.

-Dave





More information about the Python-list mailing list