Tuesday, January 12, 2010

Pinging a Hostname in C#

Using the Network Information Library in C# you can ping numerous Hostnames!

in your declarations:

using System.Net;
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 = err.Message;
}

No comments:

Post a Comment

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...