MikeSH
MikeSH

Reputation: 47

WebRequest to check server

I am trying to check if my server (local server) is up or down. I want to pass my server name: 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

I also tried to use ping. It works, but the page takes a long time to load (4 servers)

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

Upvotes: 1

Views: 186

Answers (1)

Elshan
Elshan

Reputation: 7693

Dim myRequest As WebRequest = WebRequest.Create("http://www.google.com")
' Return the response. 
Dim myResponse As String = myRequest.GetResponse().ContentType().ToString()
MsgBox(myResponse)

Upvotes: 2

Related Questions