Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Internet Connection vb.net

Tags:

vb.net

I am trying to run some vb.net code that indicates if i'm connected to the internet

If My.Computer.Network.IsAvailable Then
    MsgBox("Computer is connected.")
Else
    MsgBox("Computer is not connected.")
End If

This works fine if I'm connecting to a WiFi signal that doesn't require a login. If I connect to a public WiFi signal that I'm required to login/pay and I execute the code before completing this step it still tells me I'm connected (in theory yes but without paying/logging in I'm not)

Any ideas how set this up?

Thanks

like image 214
elmonko Avatar asked Oct 29 '13 21:10

elmonko


1 Answers

You could check for an internet connection by trying to read Google.com:

Public Shared Function CheckForInternetConnection() As Boolean
    Try
        Using client = New WebClient()
            Using stream = client.OpenRead("http://www.google.com")
                Return True
            End Using
        End Using
    Catch
        Return False
    End Try
End Function

Taken from: Here

like image 149
Chris Avatar answered Oct 09 '22 17:10

Chris