Q.: Create a Windows Application in VB.Net which is used to Check Internet Connection is available or not.
In VB.Net 2008, sometimes we have require to Check Internet Connection. This Example Shows to Check Internet Connection whether it is available or not.
Compatibility/Version: Microsoft Visual Studio 2008 (Microsoft .Net Framework 3.5)
Source Code:
Public Class Form1
Private Function InternetConnection() As Boolean
Dim req As System.Net.WebRequest =
System.Net.WebRequest.Create("http://www.google.com/")
Dim resp As System.Net.WebResponse
Try
resp = req.GetResponse()
resp.Close()
req = Nothing
Return True
Catch ex As Exception
req = Nothing
Return False
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If InternetConnection() = False Then
MessageBox.Show("No internet connection!")
Else
MessageBox.Show("Internet connection detected!")
End If
End Sub
End Class
Output:


