Thursday 17 April 2014

Check Server Status Using C#.Net

Check Server Status Using C#.Net


Hi all, This is my 200th Post. All this Journey started with a single Post in a small newbie blog @ October,2012 which has evolved into this massive Repository as of today. This site has crossed more than 0.2 Millions Pageviews from 160 Countries which itself speaks of its Popularity . I would heartily thank all the readers of this site and request you to be the part of this site in the future as well. New Ideas and Innovative thoughts are always welcomed. You can contact me Personally at my mail Id

In this Post We can see check how to check the status of the Server Using C#.Net. Its a kind of Ping Request to the Target server to check its Status. Refer the Code Snippet Below:

Design Part:

<html xmlns="" >
<head runat="server">
    <title>Check Server Status</title>
    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
        <br />
        <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label>&nbsp;</div>


using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.NetworkInformation;

public partial class CheckServerStatus : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    protected string PingSvrs(string hostname)
        string functionReturnValue = null;
        long rtTime = 0;
        Ping ping = new Ping();
            PingReply reply = ping.Send(hostname);
            if (reply.Status == IPStatus.Success)
                functionReturnValue = "G:Response Received";
                rtTime = reply.RoundtripTime;
                functionReturnValue = "R:" + hostname + " Status: " + reply.Status.ToString();
        catch (Exception ex)
            functionReturnValue = "R:" + hostname + " error: " + ex.Message;
        return functionReturnValue;

    protected void Button1_Click(object sender, EventArgs e)
        lblMsg.Text = PingSvrs(TextBox1.Text);

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top