Tutorials Forums
     Tutorials Videos
        Sign Up Now For FREE
Welcome, Guest
Username Password: Remember me

IsInternetAvailable
(1 viewing) (1) Guest
VB.NET HELP, VB.NET TUTORIALS, VB.NET CODE, VB.NET PROGRAMMING, VB.NET

Visual Basic.NET is the most recent generation of Visual Basic. Developers will be pleased to note that its new features include inheritance, method overloading, structured exception handling, and more. These capabilities make it easier than ever to create .NET applications, including Windows applications, web services, and web applications. The articles in this section give you all the tips you need to work wit this useful language.
  • Page:
  • 1

TOPIC: IsInternetAvailable

IsInternetAvailable 09 Dec 2009 15:12 #64

Check if an Internet Connection is available

Instructions:
1) Copy and paste the code into a class.
2) Read how to call the function.

 
''' <summary>
'
'' Pings a variation of websites defined in a array and checks for connectivity.
''' </summary>
'
'' <returns>True if a ping succeeded, False if otherwise.</returns>
''' <remarks></remarks>
Public Function isInternetAvailable() As Boolean
'
The arrays of sites we want to check for connectivity.
' If all fail to ping, the function will return false.
Dim sitesToCheck() As String = {"www.google.com", _
"www.microsoft.com", "www.dreamincode.net"}
 
Dim failedPings As Integer = 0
 
'
Loop through all hostnames and ping them
For Each str As String In sitesToCheck
Try
My.Computer.Network.Ping(str)
Catch ex As Exception
failedPings += 1
End Try
Next
 
' Couldn't ping any of the hostnames.
If failedPings = sitesToCheck.Length Then Return False
Return True
End Function
 
' Example Usage
MessageBox.Show(isInternetAvailable())
  • CE
  • OFFLINE
  • Administrator
  • Posts: 197
  • Karma: 78
CodersEngine
  • Page:
  • 1
Time to create page: 0.27 seconds