Dear sir,
Please check my code, i want to send sms with IP and Location.
please rectify if any error.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="lan.aspx.cs" Inherits="pingtest.lan" %>
<link href="css/StyleSheet2.css" rel="stylesheet" />
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body style="width: 515px; height: 281px">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="center">
<div class="rounded_corners" style="width: 531px; margin-center: 0px; height: 229px;">
<caption>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Height="67px" Width="533px">
<Columns>
<asp:BoundField DataField="IP" HeaderText="IP" />
<asp:BoundField DataField="Location" HeaderText="Location" />
<asp:BoundField DataField="Network latency(ms)" HeaderText="Network latency(ms)" />
<asp:TemplateField HeaderText="Status" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100">
<ItemTemplate>
<asp:Image ID="Image2" runat="server" Height="25" ImageUrl='<%# "~/img/" + (Eval("message").ToString() == "DOWN" ? "r1.jfif" : "grn1.png") %>' Width="30" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
</div>
<td class="auto-style2">
<asp:Label ID="lblTime" runat="server" Style="color: #FFFFFF; font-weight: 500; text-align: right; font-size: medium;" />
</td>
</tr>
</caption>
<asp:Timer ID="Timer1" runat="server" OnTick="TimerTick" Interval="3000" />
</ContentTemplate>
</asp:UpdatePanel>
<div>
<style type="text/css">
.blink { background: yellow; -webkit-transition: backgroundColor 0.05s ease-in-out; -ms-transition: backgroundColor 0.05s ease-in-out; transition: backgroundColor 0.05s ease-in-out; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=gvData] tr:not(:has(th)) td').each(function () {
$('[id*=gvData] tr:not(:has(th))').removeClass('blink');
var data = $(this).text().trim();
if (data.indexOf(' ') != -1) {
var row = $(this).closest('tr');
var backgroundInterval = setInterval(function () {
$(row).toggleClass("blink");
}, 500)
}
});
});
</script>
</form>
</body>
</html>
namespace pingtest
{
public partial class lan : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblTime.Text = "Last Refreshed: " + DateTime.Now.ToString();
DataTable pingResults = new DataTable();
pingResults.Columns.AddRange(new DataColumn[] {
new DataColumn("IP", typeof(string)),
new DataColumn("Location",typeof(string)),
new DataColumn("Network latency(ms)",typeof(string)),
new DataColumn("Message",typeof(string))});
// new DataColumn("Status",typeof(string))});
//flage 1
try
{
pingResults.Clear();
List<Employee> employees = GetDetails();
for (int i = 0; i < employees.Count; i++)
{
string address = employees[i].ipAddress;
long time = PingAddress(address, 1);
Ping ping = new Ping();
PingReply pingReply = ping.Send(employees[i].ipAddress);
string message = (pingReply.Status == IPStatus.Success) ? "UP" : "DOWN";
lock (pingResults.Rows.SyncRoot)
{
// pingResults.Rows.Add(employees[i].ipAddress, employees[i].Emp_Name, time);
pingResults.Rows.Add(employees[i].ipAddress, employees[i].Emp_Name, time, message);
}
Thread.Sleep(1);
}
GridView1.DataSource = pingResults;
GridView1.DataBind();
}
catch (Exception ex)
{
}
}
//flage 1
public class Employee
{
public string ipAddress { get; set; }
public string Emp_Name { get; set; }
}
//flage 1
private List<Employee> GetDetails()
{
List<Employee> employees = new List<Employee>();
string cs = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
using (SqlCommand cmd = new SqlCommand("SELECT emp_nm,ip_add FROM nms where flag='1'", con))
//uusing (SqlCommand cmd = new SqlCommand("SELECT emp_nm,ip_add FROM nms ", con))
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
employees.Add(new Employee
{
Emp_Name = sdr["emp_nm"].ToString(),
ipAddress = sdr["ip_add"].ToString(),
});
}
con.Close();
}
}
return employees;
}
private static long PingAddress(string address, int timeout)
{
try
{
Ping pingClass = new Ping();
PingReply pingReply = pingClass.Send(address, timeout);
return pingReply.RoundtripTime;
}
catch (Exception e)
{
}
return -1;
}
protected void OnDataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
cell.Text = "AAQMS Status Location Wise";
cell.ColumnSpan = 5;
row.Controls.Add(cell);
// cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
// cell.Text = "Employees";
// row.Controls.Add(cell);
row.BackColor = ColorTranslator.FromHtml("#647C90");
GridView1.HeaderRow.Parent.Controls.AddAt(0, row);
}
protected void TimerTick(object sender, EventArgs e)
{
lblTime.Text = "Dt:" + DateTime.Now.ToString();
// GridView1.DataBind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (!string.IsNullOrEmpty(e.Row.Cells[4].Text))
{
if (e.Row.Cells[3].Text == "UP")
{
e.Row.Cells[3].ForeColor = System.Drawing.Color.Black;
e.Row.Cells[3].BackColor = System.Drawing.Color.Green;
}
else
{
e.Row.Cells[3].ForeColor = System.Drawing.Color.Black;
e.Row.Cells[3].BackColor = System.Drawing.Color.Red;
}
if (e.Row.Cells[3].Text == "UP")
{
string IP = e.Row.Cells[1].Text;
string lcn = e.Row.Cells[2].Text;
string SMSurl = "SMS Gate ways and Url";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
}
}
if (e.Row.Cells[3].Text == "DOWN")
{
string IP = e.Row.Cells[1].Text;
string lcn = e.Row.Cells[2].Text;
string SMSurl = "SMS Gate ways and Url";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
}
}
}
}
}