I am posting here the code snippet to Ping a given IP address using c#.net
ÂÂ
C#.net Section  -Sample.aspx.cs
using System;
using System.Data;
using System.Configuration;
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;
using System.Net.NetworkInformation;
using System.Text;
public partial class _Default : System.Web.UI.PageÂÂ
{
protected void Page_Load(object sender, EventArgs e)
{ÂÂ
}protected void btnSubmit_Click(object sender, EventArgs e)
{
try {
lblStatus.Text = null;
Ping ping = new Ping();
PingReply pingreply = ping.Send(txtHost.Text);
txtPing.Text += "Address: " + pingreply.Address + "\r";
txtPing.Text += "Roundtrip Time: " + pingreply.RoundtripTime + "\r";
txtPing.Text += "TTL (Time To Live): " + pingreply.Options.Ttl + "\r";
txtPing.Text += "Buffer Size: " + pingreply.Buffer.Length.ToString() + "\r";
}
catch (Exception err) {
lblStatus.Text = err.Message;
}
}
}
Here is the design section
Sample.aspx
<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc"><tr>ÂÂ</table><td width="100" align="right" bgcolor="#eeeeee" class="header1">Hostname/IP:</td> <td align="center" bgcolor="#FFFFFF"> <asp:TextBox ID="txtHost" runat="server"></asp:TextBox> <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" /></td></tr> <tr><td width="100" align="right" bgcolor="#eeeeee" class="header1">Ping Results:</td> <td align="center" bgcolor="#FFFFFF"> <asp:TextBox ID="txtPing" runat="server" Height="66px" TextMode="MultiLine" Width="226px"></asp:TextBox> <br /> <asp:label ID="lblStatus" runat="server"></asp:label></td></tr>

Discussion
No comments for “Ping IP address using c#.net”