This is a very simple page to list server status, I use an updatePanel and 1 count down clock to refresh this panel every 60 seconds.

Behind the clock is a C# ping method that get the server status(up or down), then write to the labels on the page.

 

ServerStatus.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ServerStatus.aspx.cs" Inherits="ServerStatus" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:Timer ID="Timer2" runat="server" ontick="CD_Ticker"  Interval="1000"></asp:Timer>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table style="width:100%;">
                <tr>
                    <td> This page will refresh after <asp:Label ID="CDLabel" runat="server" Text="60" ></asp:Label> seconds.</td>
                </tr>
                <tr>
                    <td>Server1</td>
                    <td>Server2</td>
                    <td>Server3</td>
                    <td>Server4</td>
                </tr>
                <tr>
                    <td><asp:Label ID="Label1" runat="server" ForeColor="black"></asp:Label></td>
                    <td><asp:Label ID="Label2" runat="server" ForeColor="black"></asp:Label></td>
                    <td><asp:Label ID="Label3" runat="server" ForeColor="black"></asp:Label></td>
                    <td><asp:Label ID="Label4" runat="server" ForeColor="black"></asp:Label></td>
                </tr>
              </table>
        </ContentTemplate>
    <Triggers>   
            <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="tick" /> 
    </Triggers>
    </asp:UpdatePanel>
    
    </div>
    </form>
</body>
</html>

ServerStatus.Aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.NetworkInformation;
using System.Drawing;
using System.Windows.Forms;
using System.Windows;
public partial class ServerStatus : System.Web.UI.Page
{
    /* Initialize the page while checking servers */
    protected void Page_Load(object sender, EventArgs e)
    {
         ServerCheck(); 
    }
    /* Count Down clock and run server check every 60 Seconds */
    protected void CD_Ticker(object sender, EventArgs e)
    {
        if (Convert.ToInt32(CDLabel.Text).Equals(0))
        {
            CDLabel.Text = "60";
            ServerCheck();
        }
        else
        {
            CDLabel.Text = Convert.ToString((Convert.ToInt32(CDLabel.Text) - 1));
        }
    }
    /*you can put the list here, or use table however I dont have so many server to be listed so far */
    public void ServerCheck()
    {
        FindAndPrint("10.0.0.1", "Label1");
        FindAndPrint("10.0.0.2", "Label2");
        FindAndPrint("10.0.0.3", "Label3");
        FindAndPrint("10.0.0.4", "Label4");
    }
    /*this will check the IPaddress then modify the related Label */
    public void FindAndPrint(String IPaddress, String LabelName)
    {
        System.Web.UI.WebControls.Label l = (System.Web.UI.WebControls.Label)FindControl(LabelName);
/* if you are using Master Template, you need use those code to replace the top line 
ContentPlaceHolder temCont = (ContentPlaceHolder)Master.FindControl("MainContent");
Label l = (Label)temCont.FindControl(LabelName);*/
        if (IsConnected(IPaddress))
        {
            l.Text = "Online";
            l.BackColor = Color.Green;
            l.BorderColor = Color.Black;
        }
        else
        {
            l.Text = "Offline";
            l.BackColor = Color.Red;
            l.BorderColor = Color.Yellow;
        }
    }
    /* a ping method to return true or false on ping server */
    public static bool IsConnected(String IPaddress)
    {
        bool result = false;
        Ping p = new Ping();
        try
        {
            PingReply reply = p.Send(IPaddress, 3000);
            if (reply.Status == IPStatus.Success)
                return true;
        }
        catch { }
        return result;
    }
}

 

About Lei

I am an IT specialist with over 10 year experience - years on Automation, on-Premise or Azure.

I am happy to develop however never want be a full time developer. Only do what I have to do. If it has to be PowerShell,HTML, PHP, CSS, C#, VBS or JS, front end or backend, so be it, doesn't matter!

Spent years with Windows, SCCM, SharePoint, SQL and Exchange servers. For last several years, I have been actively working under On Premise > Azure environment.

THERE IS NO WAY BACK!!!

Current Certificates:
    Microsoft® Certified-
  • -Enterprise Administrator
  • -Database Administrator
  • -SharePoint Administrator
  • -Administering and Deploying SCCM 2012
Red Hat Certified Technician
ITIL V3 Foundation - Practitioner

Working on Azure Certificates now and hopefully they can stop upgrading their questions one day! GIVE ME A BREAK!

Contact Lei

Name *
Email *
Comments *

Traffic since 10/08/2016

Today53
Yesterday83
This week677
This month1973
Total416333

Visitor Info

  • IP: 54.227.51.103
  • Browser: Unknown
  • Browser Version:
  • Operating System: Unknown

Who Is Online

1
Online

2017-12-17

Login