09-10-16, 09:59 PM
كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FirstUrl As New System.Uri("http://www.yourURLhere.com/")
Dim OtherURl As New System.Uri("http://www.dreamincode.net/forums/topic/137663-check-if-url-exists/")
If isServerAccessible(FirstUrl) = True Then
MessageBox.Show("Work")
Else
MessageBox.Show("Not Work")
End If
If isServerAccessible(OtherURl) = True Then
MessageBox.Show("Work")
Else
MessageBox.Show("Not Work")
End If
End Sub
Private Function isServerAccessible(ByVal HostAddress As Uri) As Boolean
Try
'First check if the computer has net access at all.
'Second check if the host is reachable and how good the speed of respond is.
'The host address can be a computer name, IP-address or you can create URL form Uri class.
If My.Computer.Network.IsAvailable AndAlso My.Computer.Network.Ping(HostAddress, 1000) Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Functionاستخدمه بالطريقة التي تناسبك ، بالاضافة يجب عليك التحقق هل يوجد بالاساس مشكله بالاتصال بالسيرفر ام لا يوجد انترنت بجهازك و هذه الطريقة تعمل على ذلك ، تتحقق هل انت متصل بالانترنت بالاساس ام لا ثم تفحص وجود URL على الويب .
بالتوفيق
اسم معرفي : محمد يحيى
