Using the Network Information Library in C# you can ping numerous Hostnames!
in your declarations:
using System.Net.NetworkInformation;
in your body of code:
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 = 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;
}
No comments:
Post a Comment