Created
March 25, 2014 05:24
-
-
Save wislon/9755682 to your computer and use it in GitHub Desktop.
C# ICMP Echo example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.