Dear Sir,
How to check internet download and upload speed using asp c# again ip address
please help me sir to complate my task.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="emp.aspx.cs" Inherits="intnt_mntrng_sys.emp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1">
<tr>
<td class="auto-style2">Employees Internet Status </td>
</tr>
<tr>
<td>
<asp:GridView runat="server" ID="GridView1" OnRowDataBound="OnRowDataBound" datakey="Id" />
</td>
</tr>
<asp:Label ID="lblDownloadSpeed" runat="server" Text="Label"></asp:Label>
</table>
</div>
</form>
</body>
</html>
using System.Configuration;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
namespace intnt_mntrng_sys
{
public partial class emp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable pingResults = new DataTable();
pingResults.Columns.AddRange(new DataColumn[] {
new DataColumn("Date", typeof(DateTime)),
new DataColumn("IP", typeof(string)),
new DataColumn("MacAddress",typeof(string)),
new DataColumn("MachineName",typeof(string)),
new DataColumn("Message",typeof(string)),
new DataColumn("Emp_name",typeof(string)),
new DataColumn("Internet_Speed",typeof(string)),
new DataColumn("Internet_Speed_(U)",typeof(string))});
try
{
pingResults.Clear();
List<Employee> employees = GetDetails();
for (int i = 0; i < employees.Count; i++)
{
Ping ping = new Ping();
PingReply pingReply = ping.Send(employees[i].ipAddress);
string message = (pingReply.Status == IPStatus.Success) ? "On" : "Off";
lock (pingResults.Rows.SyncRoot)
{
{
pingResults.Rows.Add(DateTime.Now, employees[i].ipAddress, GetMacAddress(employees[i].ipAddress), GetMachineName(employees[i].ipAddress), message, employees[i].Emp_Name);
}
Thread.Sleep(100);
}
// lblDownloadSpeed.Text = string.Format("Download Speed: {0}KB/s", speeds.Average());
GridView1.DataSource = pingResults;
GridView1.DataBind();
}
}
catch
{
}
}
public class Employee
{
public string ipAddress { get; set; }
public string Emp_Name { get; set; }
}
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 emp_ip", 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;
}
public string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = "arp";
pProcess.StartInfo.Arguments = "-a " + ipAddress;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
string[] substrings = strOutput.Split('-');
if (substrings.Length >= 8)
{
macAddress = substrings[3].Substring(Math.Max(0, substrings[3].Length - 2))
+ "-" + substrings[4] + "-" + substrings[5] + "-" + substrings[6]
+ "-" + substrings[7] + "-"
+ substrings[8].Substring(0, 2);
return macAddress;
}
else
{
return "not found";
}
}
private string GetMachineName(string ipAdress)
{
string machineName = string.Empty;
try
{
IPHostEntry hostEntry = Dns.GetHostEntry(ipAdress);
machineName = hostEntry.HostName;
}
catch (Exception ex)
{
}
return machineName;
}
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[4].Text == "On")
{
e.Row.Cells[4].ForeColor = System.Drawing.Color.Black;
e.Row.Cells[4].BackColor = System.Drawing.Color.Green;
}
else
{
e.Row.Cells[4].ForeColor = System.Drawing.Color.Black;
e.Row.Cells[4].BackColor = System.Drawing.Color.Red;
}
}
if (e.Row.Cells[4].Text == "Off")
{
string IP = e.Row.Cells[1].Text;
string lcn = e.Row.Cells[5].Text;
string msg = e.Row.Cells[4].Text;
String date = e.Row.Cells[0].Text;
string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&to=919667044472.&text=Service at AAQMS is down, IP : " + IP + ", Location:" + lcn + ", Date/Time : " + date + "- Meja Urja Nigam PVT. Ltd.&from=MUNPLA &indiaDltContentTemplateId=1207164697517002212&indiaDltPrincipalEntityId=1201159222154902387";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
}
}
}
}
}