using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.NetworkInformation; namespace TestPing { class Program { // args[0] can be an IPaddress or host name. public static void Main(string[] args) { Ping pingSender = new Ping(); PingOptions options = new PingOptions(); // Use the default Ttl value which is 128, // but change the fragmentation behavior. options.DontFragment = true; // Create a buffer of 32 bytes of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; try { PingReply reply = pingSender.Send(args[0], timeout, buffer, options); Console.WriteLine("reply.Status {0} {1}", args[0], reply.Status.ToString()); if (reply.Status == IPStatus.Success) { Console.WriteLine("Address: {0}", reply.Address.ToString()); Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime); if (reply.Options != null) // reply.Status==Success but reply.Options is empty // for a ping from ipv6-adress to ipv6-adresses { Console.WriteLine("reply.Options:"); 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); } } catch(Exception ex) { Console.WriteLine("Exception {0}", ex.InnerException.Message); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)