Click here to Skip to main content
15,918,123 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 code

What I have tried:

Public Function isInternetConnected(Optional pUrl As String = "") As Boolean

        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.
Updated 23-Apr-23 11:24am
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:

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

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

ENd Function

It works correctly in most cases.
Share this answer

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