Skip to content

Instantly share code, notes, and snippets.

@wislon
Created March 25, 2014 05:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wislon/9755682 to your computer and use it in GitHub Desktop.
Save wislon/9755682 to your computer and use it in GitHub Desktop.
C# ICMP Echo example
// Add a reference to (and using) System.Net.NetworkInformation
string addressOrIp = "127.0.0.1";
Ping ping = new Ping();
PingReply reply = ping.Send(addressOrIp);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine ("Address: {0}", reply.Address.ToString ());
Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
}
else
{
Console.WriteLine (reply.Status);
}
@kbabuadze
Copy link

It does not work well in case ping fails. Unhandled exception error pops up. even with catch and try it works but it slows down an application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment