Click here to Skip to main content
15,074,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to check internet connection is available by vb.net code

What I have tried:

Public Function isInternetConnected(Optional pUrl As String = "http://www.google.com") As Boolean

    Try
        Using client = New WebClient()
            Using stream = client.OpenRead(pUrl)
                Return True
            End Using
        End Using
        Return IsConnectedToInternet(pUrl)
    Catch ex As Exception
        Return IsConnectedToInternet(pUrl)

    End Try
End Function


This code sometimes returns false when internet connection is available.
Posted
Updated 27-Oct-20 1:09am
Comments
CHill60 27-Oct-20 7:09am
   
You haven't shared the code that actually does the check - i.e. IsConnectedToInternet

1 solution

There's no 100% working solution for this, but you can try:

VB
'reference to System.Net and System.Net.NetworkInformation is required!
Function IsInternetConnected() AS Boolean

	Return New Ping().Send("www.google.com").Status = IPStatus.Success

ENd Function


It works correctly in most cases.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900