Checking an Internet Connection 
Author Message
 Checking an Internet Connection

I'm writing an application that works with the Internet and I need a way to
test if the computer is currently connected to the Internet.  I know how to
check for a modem connection using the registry.  But for T1, DSL and cable
modem users I can't find a fast way.  I have tried playing with the
GetInternetConnectionState API from wininet.dll but it reports connected if
the computer is logged on to a network regardless of whether the Internet
connection is working.  I've tried using the InternetOpenUrl API as well to
request a page but that takes around 45 seconds to return an answer if the
connection is down.

Does anyone know a fast and reliable way to confirm that an Internet
connection is good?  Waiting 45 seconds just doesn't cut it...

Thanks,
Dan



Sun, 15 Feb 2004 13:52:10 GMT  
 Checking an Internet Connection
Try http://www.mvps.org/vbnet/
Search for ....
Determining Network Connections with InternetGetConnectedState


Quote:
> I'm writing an application that works with the Internet and I need a way
to
> test if the computer is currently connected to the Internet.  I know how
to
> check for a modem connection using the registry.  But for T1, DSL and
cable
> modem users I can't find a fast way.  I have tried playing with the
> GetInternetConnectionState API from wininet.dll but it reports connected
if
> the computer is logged on to a network regardless of whether the Internet
> connection is working.  I've tried using the InternetOpenUrl API as well
to
> request a page but that takes around 45 seconds to return an answer if the
> connection is down.

> Does anyone know a fast and reliable way to confirm that an Internet
> connection is good?  Waiting 45 seconds just doesn't cut it...

> Thanks,
> Dan



Mon, 16 Feb 2004 03:27:02 GMT  
 Checking an Internet Connection
Try this...

Public Declare Function RasEnumConnections Lib "RasApi32.dll" Alias
"RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As
Long) As Long
Public Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias
"RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long

Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxDeviceType = 16
Public Const RAS95_MaxDeviceName = 32

Public Type RASCONN95
    dwSize As Long
    hRasCon As Long
    szEntryName(RAS95_MaxEntryName) As Byte
    szDeviceType(RAS95_MaxDeviceType) As Byte
    szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
'
Public Type RASCONNSTATUS95
    dwSize As Long
    RasConnState As Long
    dwError As Long
    szDeviceType(RAS95_MaxDeviceType) As Byte
    szDeviceName(RAS95_MaxDeviceName) As Byte
End Type

Public TRasCon(255) As RASCONN95

Public Function IsConnected() As Boolean
Dim lg As Long
Dim lpcon As Long
Dim RetVal As Long
Dim Tstatus As RASCONNSTATUS95
'
TRasCon(0).dwSize = 412
lg = 256 * TRasCon(0).dwSize

RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
If RetVal <> 0 Then
   MsgBox "SessionController.900I " & strMsgErro01 & RetVal
   Exit Function
End If
'
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
If blnEncerraConex?o And Not IsMissing(RetCode) Then
    RetCode = Tstatus.RasConnState
End If
If Tstatus.RasConnState = &H2000 Then
   IsConnected = True
Else
   IsConnected = False
End If

End Function


Quote:
> I'm writing an application that works with the Internet and I need a way
to
> test if the computer is currently connected to the Internet.  I know how
to
> check for a modem connection using the registry.  But for T1, DSL and
cable
> modem users I can't find a fast way.  I have tried playing with the
> GetInternetConnectionState API from wininet.dll but it reports connected
if
> the computer is logged on to a network regardless of whether the Internet
> connection is working.  I've tried using the InternetOpenUrl API as well
to
> request a page but that takes around 45 seconds to return an answer if the
> connection is down.

> Does anyone know a fast and reliable way to confirm that an Internet
> connection is good?  Waiting 45 seconds just doesn't cut it...

> Thanks,
> Dan



Mon, 16 Feb 2004 02:47:40 GMT  
 Checking an Internet Connection

Quote:
> I've tried using the InternetOpenUrl API as well to
> request a page but that takes around 45 seconds to return an answer if the
> connection is down.

Not to mention that the above can cause some people's systems to dial-up the
net to try connecting to the URL, which could cost them money...


Sat, 21 Feb 2004 19:12:06 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Advanced: CHECK for Internet Connection

2. Check for internet connection

3. Checking an Internet Connection

4. Checking for Internet connection

5. checking for internet connection in NT

6. How to check for internet connection?

7. Check for internet connection

8. Advanced: CHECK for Internet Connection

9. Checking for Internet Connection

10. Check if internet connection is up.....

11. Check for Internet Connection

12. checking internet connection from .net

 

 
Powered by phpBB® Forum Software