Link to home
Start Free TrialLog in
Avatar of PhilMa
PhilMa

asked on

How to detect if Internet is online/offline

Hi to all,

I'm going to  write a Programm, with MS VC++ 6.0 under WIN NT and I want to know how I can detect if an Internet session is online / offline. It must work with all connection type ( modem, lan, proxy etc.)

How can i do this ??

thanks for your time and thanks in advance

PhilMa

Avatar of jhance
jhance

That depends on what you define as "internet session".

What do you really want to know?  

If the question is: "can I open a connection to X?" then there are several ways of doing that but they all involve testing the connection and seeing if it works.

If the supposed question is: "am I connected to the internet?" then the answer is no.  What is the internet anyway?  It's not a thing to be connected to.  Your computer is either connected to a local network via a LAN card or to a service provider via a modem, etc.  So you're back to the first part of this comment.  All you can do is test various sites and see if connections can be made.

In Windows there is the InternetGetConnectedState function in WININET.DLL but it's use can be highly confusing to those who don't understand what it's saying.  All it knows is if a network connection is potentially available, NOT it a particular site can be reached.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PhilMa

ASKER

Hi jhance,

Thanks for your answer, I want to know if a network connection is online or offline.

If I understand you right, InternetGetConnectedState() checks only if the computer is equiped with a network card or a modem  to connect to the internet via LAN or an Service provider.

How can i detcect, if i can reach a site? Maybe you have an example

PhilMa
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, it wasn't jhance, it was me :o)

>>If I understand you right, InternetGetConnectedState()
>>checks only if the computer is equiped with a
>>network card or a modem  to connect to the internet via
>>LAN or an Service provider


From the docs:

"InternetGetConnectedState
BOOL InternetGetConnectedState(
    OUT LPDWORD lpdwFlags,
    IN DWORD dwReserved
);

Retrieves the connected state of the local system.

Returns TRUE if there is an Internet connection, FALSE otherwise. "

IT checks if there's a connection through either a modem or a NIC, not whether the system is equipped with that (well, you could assume that if there's a connection through a NIC, that the system is equipped with one :o)
'InternetGetConnectedState()' - what should I add :o)