Determining if a client PC has an Internet connection

Jarek Zgoda jzgoda at gazeta.usun.pl
Sun Sep 19 04:49:21 EDT 2004


Thorsten Kampe <thorsten at thorstenkampe.de> pisze:

>>> Is there any way to reliably determine the state of the client's
>>> internet connectivity?
>> 
>> No, there's no such way.
> 
> I think there has to be (or at least there is a method that many
> coders use because "testing if you're online" is a very frequent
> problem).

There has to be, but isn't. I often see this question on many forums
with single answer. Let me cite ICS FAQ:

"""
There is no perfect solution. Why? Because the Internet is just another
network. Your computer does not distinguish between LAN and Internet.
They are both networks. One of them just happens to be very big.

The Internet is no different to your local network. It is just a matter
of size.

Think about your question. "Am I connected to the Internet?". Try
rephrasing your question to what you really want to ask. "Can I connect
to a specific remote host?" With the question worded like this, you can
start to tackle the problem. How do you find out if you can connect to
the remote host? Try to connect. Simple as that. If the connection
attempt fails, there is no path between you and the remote host or the
remote host is refusing connections.

But, I hear you cry, I do not want the auto-dial the pop up. How do we
get around this? Ask the user how to make a connection. We see this all
the time in other Internet applications. Outlook Express, WinAmp, etc.
They ask the user what sort of network connection they have. From this
information, the applications can make the best choice about how to
connect to a remote host.

There is no proof way. However some things can help.

There is an InternetGetConnectedState function in the WinINet.DLL that
returns true if it detects a connection to the internet. However, the
only thing you can be sure about when using this funtion is that the
computer will not start dialing and not pop up any dialog box when the
function returned true and you afterwards try to do anything on the
internet. In some cases the function may return false although the
computer is connected.
"""

Although it is Win32-only.

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



More information about the Python-list mailing list