01-20-2012، 12:49 PM
(آخرین تغییر در ارسال: 01-20-2012، 12:50 PM توسط Amin_Mansouri.)
Check if an Internet Connection is available
کد پیاچپی:
''' <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())
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg