我正在尝试检查我的服务器(本地服务器)是启动还是关闭。我想传递我的服务器名称: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