Network Line and Internet Connection Check FAQ
Each function was tested on Windows 98, Windows NT SP6a, Windows 2000 , and Windows XP operating systems with a modem dialup and network card connection (except for Windows XP where a modem was unavailable).
As seen below, the behavior of the connection testing APIs was much more predictable and stable in systems with a modem dialup connection.
Alll tests were done by unplugging the physcal cable from the machine.
The RasEnumConnections() API works well on all the systems, but is only available for testing modem connections.
The next set of APIs tested work for non-modem network connections as well:
1) IsNetworkAlive()
2) InernetGetConnectedState()
3) InternetCheckConnection()
4) IsDestinationReachable()
1) IsNetworkAlive()
With a modem dialup connection, this API works as documented on
all four OS's. NETWORK_ALIVE_LAN and NETWORK_ALIVE_WAN return TRUE if a connection exists, and
FALSE if no connection.
With a network card connection, this API initially always returns TRUE regardless of the physical connection state for all OS's, but after a call to InternetCheckConnection()
returns FALSE (after waiting for a timeout - see below) calling IsNetworkAlive() correctly returns
FALSE if the cable is unplugged.
2) InternetGetConnectedState() :
This API was tested with a verified, valid URL. With a modem dialup connection, the function works as documented, on all four OS's.
With a network card connection, the function returns TRUE in all four OS's when plugged in.
With the cable unplugged the function continues to return TRUE for some time, but after a time-out it will
return FALSE. When the cable is plugged back in the function will return TRUE only after a time-out period has elapsed.
On Windows 98, this function always
returns TRUE, regardless of the state of the connection.
3) InternetCheckConnection():
With a modem dialup connection, this function works as documented in
all four OS's. With a network card connection, when plugged in, it returns TRUE on Windows NT, Windows 2000, and Windows XP.
On Windows 98 this function caused the test application to fault (under investigation).
On Windows NT, with the cable unplugged, the function returns FALSE (denoting an error) after a time-out period. GetLastError() returns 0, which is unusual.
On Windows 2000 this function behaves similarly to
InternetGetConnectedState(); it will return the correct value after a time-out period.
4) IsDestinationReachable() :
This function is only available on Windows ME and Windows 2000.
With a modem dialup connection, this function works as documented. With a network card connection, this function returns TRUE when the cable is plugged in, and returns FALSE when the cable is unplugged. Unfortunately, after a FALSE return, GetLastError() returns 0.
The last test was with the IP Helper APi GetIfEntry(), which returns the status of a adapter adapter.
On Windows 98, Windows NT, and Windows 2000, using a modem dialup connection, GetIfEntry() sets the dwAdminStatus and dwOperStatus members of the MIB_IFROW structure equal to MIB_IF_OPER_STATUS_UNREACHABLE.
On Windows XP ( the only OS with a network card connection tested), the dwOperStatus member was set to MIB_IF_OPER_STATUS_OPERATIONAL when network cable was plugged in, and set to MIB_IF_OPER_STATUS_NON_OPERATIONAL if the cable was unplugged.
dwAdminStatus was set to MIB_IF_OPER_STATUS_UNREACHABLE in both cases.
On Windows XP it is possible to check the status of a connection very easily by using GetIfEntry().
On Windows 2000 and Windows XP, it may be possible to check the connection state via WMI.
Another possibility for connection status checking is to use DeviceIOControl() to query the driver about the connection state.
Arkady Frenkel , Microsoft MVP [Windows SDK/Networking]