Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Computer.Network.Ping("tiancao.net") Then
MsgBox("能访问网站")
Else
MsgBox("网站访问受限")
End If
'Dim HTTP As New System.Net.WebClient
'Try
' Dim Str As String = HTTP.DownloadString("
http://www.tiancao.net") ' MsgBox("网站正常访问")
'Catch ex As Exception
' MsgBox("网站访问中出现异常")
'End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim req As HttpWebRequest = CType(WebRequest.Create("
http://www.tiancao.net"), HttpWebRequest)
Dim resp As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
If resp.StatusCode = HttpStatusCode.OK Then
resp.Close()
MsgBox("true")
End If
Catch webex As WebException
MsgBox("False")
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If My.Computer.Network.IsAvailable = True Then
'如果可用
MsgBox("可用")
Else
'不可用
MsgBox("不可用")
End If
End Sub