Program to Check Internet Connection is Available or Not In VB.Net

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:

Download Now (.Zip File 94 KB)…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.