In order to check for an internet connection you need to use the Windows API function InternetGetConnectedState which returns either true or false. You can also get the connection type from the dwFlags parameter. In our example I will popup a dialog box but you can do what ever you deem necessary with the results according to your specific needs.
'Declare the API function
Private Declare Function InternetGetConnectedState Lib "wininet" _
(ByRef dwFlags As Long, ByVal dwReserved As Long) As Long
'Define possible connection types
Private Enum ConnectStates
LAN = &H2
Modem = &H1
Proxy = &H4
Offline = &H20
Configured = &H40
RasInstalled = &H10
End Enum
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lng_dwFlags As Long
Dim blnConnected As Boolean = (InternetGetConnectedState(lng_dwFlags, 0&) <> 0)
Dim strMessage As String
Dim ConnectionType As ConnectStates
If blnConnected Then
strMessage += "Computer is Connected" & ControlChars.NewLine
'Display the connection flags
strMessage += "Connection Flags: " & ControlChars.NewLine
For Each connectiontype In _
System.Enum.GetValues(GetType(ConnectStates))
If (ConnectionType And lng_dwFlags) = ConnectionType Then
strMessage += " " & ConnectionType.ToString() & ControlChars.NewLine
End If
Next
End If
MessageBox.Show(strMessage)
End Sub
'This code does not verify that a connection is active just that the computer is currently configured for the internet.