We always want make a web page that can show the web server status, see if some server is down with a graphic shows, and here we go.
The idea is using vb ping method to get the server response from the IP, and we made a sql database table include all the ips of the servers and server information, write a vb method to test the IP and return a value, on the front end of asp.net, we can use the template filed to utilize that value and generate a graphic within the same row of the table.
Here we focus on ping so won`t give much detail of gridview. Through my table you can roughly see what we have and customize your own table. Basically our table contains general information of our server and switches. To change this we want make a separate page because I `d rather to keep it simple.
We need create a new page p.aspx under our website, and go to p.aspx.vb(I use separated files) put our ping method,
Start with the vb ping method

 

 

'p.aspx.vb
Imports System Imports System.Net Imports System.Net.NetworkInformation Imports System.Text Partial Class p Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Public Function getPing(ByVal sender As String) As String Dim pingSender As New Ping() Dim options As New PingOptions() ‘ Use the default Ttl value which is 128, ‘ but change the fragmentation behavior. options.DontFragment = True ‘ Create a buffer of 32 bytes of data to be transmitted. Dim data As String = “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa” Dim buffer() As Byte = Encoding.ASCII.GetBytes(data) Dim timeout As Integer = 1200 Dim reply As PingReply = pingSender.Send(Trim(sender), timeout, buffer, options) If reply.Status = IPStatus.Success Then Return “true.png” Else Return “false.png” End If End Function End Class

 We can see from the function getPing(<IP>),it will return the value we need. Because I have multiple ping around 10 same time, I put time out as 1.2 sec, otherwise it is not accurate. In the front end, we put the gridview in, and duplicate one more column as IP column, then we change it into template field. Under template field, we put this in: 

<asp:BoundField DataField=”Model_OS” HeaderText=”Model_OS”
                SortExpression=”Model_OS” />
<asp:TemplateField HeaderText=”Status” SortExpression=”IP”>
                <EditItemTemplate>
                    <asp:TextBox ID=”TextBox1″ runat=”server” Text=’<%# Bind(“IP”) %>’></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Image  ImageUrl=’<%# getPing(DataBinder.Eval(Container.DataItem,”IP”)) %>’ runat=”server” Width=”30″ >
                       </asp:Image>
                </ItemTemplate>
            </asp:TemplateField>
<asp:BoundField DataField=”Note” HeaderText=”Note”
                 SortExpression=”Note” />

Which will load the image through the fuctionPing returned result, and list it on the gridview. And the result look like this:

Sorry due to security issue I have to clean our private data. Hopefully this makes sense. Let me know if you have problem with this tutorial and I will try to help with my limited understanding of it.


Also, it is just an example of how to utilize function in asp.net. as long as we know <%# getPing(DataBinder.Eval(Container.DataItem,”IP”)) %>, we can put it anywhere using our imagination. Or customize more item template according to your need. Or not even use database if you do not have many ips to monitor. It is flexible.

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

Today13
Yesterday83
This week637
This month1933
Total416293

Visitor Info

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

Who Is Online

1
Online

2017-12-17

Login