WebRequest进行检查服务器



我正在尝试检查我的服务器(本地服务器)是向上还是向上。我想通过我的服务器名称:myDevServer12(http://www.example.com/ss.asp)

Public Function CheckServer(ByVal ServerName As String) As Boolean
    Try
        Dim request As WebRequest = WebRequest.Create(ServerName)
        Dim response As WebResponse = request.GetResponse()
        imgServer1.ImageUrl = ("~/Images/green_light.png")
    Catch ex As Exception
        imgServer1.ImageUrl = ("~/Images/red_light.png")
        Return False
    End Try
    Return True
End Function

我也尝试使用ping。它有效,但是页面需要很长时间才能加载(4个服务器)

Dim ping As New Ping
Try
    Dim pingreply = ping.Send(lblServer1.Text, 2000)
    If pingreply.Status = IPStatus.Success Then
        imgServer1.ImageUrl = ("~/Images/green_light.png")
    Else
        imgServer1.ImageUrl = ("~/Images/red_light.png")
    End If
Catch ex As Exception
    imgServer1.ImageUrl = ("~/Images/red_light.png")
End Try
Dim myRequest As WebRequest = WebRequest.Create("http://www.google.com")
' Return the response. 
Dim myResponse As String = myRequest.GetResponse().ContentType().ToString()
MsgBox(myResponse)

相关内容

  • 没有找到相关文章

最新更新