Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting Connection to the Internet

0 views
Skip to first unread message

Al Givanecci

unread,
Apr 8, 2002, 8:33:29 AM4/8/02
to
I'm writing an application which needs to download updates from our server.
I'm trying to detect if the computer is currently connected to the internet,
and i DO NOT want to pop-up any dial-on-demand dialogs.

I couldn't find any *sure* method of doing so... the best I could find is
http://www.pcausa.com/resources/InetActive.txt.

so I came up with the following:
1. Checking if there's a RAS connection (with RasEnumConnection and
RasGetConnectionState for each Ras Connection)
2. Checking if there's a LAN/WAN connection (with IsNetworkAlive) - I'm
aware that this will be TRUE for any lan, not necessarily connected to the
internet.
3. if either of the above is TRUE, try to connect to our web server (which
should be generally accessible even through firewalls). I don't want to use
PING, because some networks block ICMP (like a some lan+nat configurations
using WinGate)
4. if I could read the web page - I'm connected.

Is there a better way to do that?
and, I would appriciate comments on the above steps.

Thanks,
Al G


David Whitman

unread,
Apr 8, 2002, 1:54:48 PM4/8/02
to
The short answer is that there's no guaranteed way to determine that
you're connected to the Internet. There's WinInet functions, but they
depend on how Internet Explorer is configured and can return
false-positives under fairly trivial circumstances.

In general, I typically just recommend that folks attempt to establish
a connection to the server. If there's no net connection, then of
course the connection attempt will fail; if the server's up, then
you'll connect and all is well. If the server's down, then knowing
that you have a net connection is not going to be particularly useful
in actually establishing the connection.

If you're concerned about the dreaded dial-up networking dialogs
rearing their head (particularly with an unattended application), then
you can deal with that directly by checking to see:

1. Does the system have any dial-up networking connectiods? If no,
then it's safe to assume that the user isn't using DUN to connect to
the net.

2. If there are one or more connectiods, check to see if there's any
connections currently established (ie: active dial-up sessions). If
there is, then continue on; if there isn't, then you know that there's
at least a chance that a dial-up connection will be required. In other
words, it's going to be easier to make the decision based on the
absence of something (a dial-up connection) rather than the presence
of something (a connection to the internet by some means). Many
applications (ie: Explorer, Eudora, Agent, etc.) give their users
configuration options that look something like this:

A. I am directly connected to the Internet (read: don't worry about
dial-up networking, just try to connect and let the chips fall where
they may).

B. I use dial-up networking. If a connection is not established, use
this connectoid (read: if there is a DUN connection, use it;
otherwise,establish one using the connectoid I've provided you with).

C. I use dial-up networking, but only use this connectoid (read: if
there's a DUN connection, make sure that the current connection used
this connectoid; if not, then don't establish the connection; if
there's no connection, use the connectoid I've provided you with).

This last option is important because folks may have multiple DUN
connectoids, and some of them may connect to a corporate WAN or other
private network that is not "the Internet", so you want to make sure
you don't try to connect if that connectoid is in use.

Lastly, another option, but one that should be really used against
your own servers, is to throw an ICMP echo datagram (ie: a ping)
against the server's IP address and see if you get a response. This
sort of thing is fine for a specific purpose application talking to
it's own servers, but would be completely inappropriate for a general
purpose application such as an email client.

David

----
David Whitman <da...@catalyst.com> | Integrate software updates in your
Catalyst Development Corporation | application with ActivePatch. Download
http://www.catalyst.com/ | the SDK from www.activepatch.com

0 new messages