PingOptions Class
Collapse the table of content
Expand the table of content

PingOptions Class


Used to control how Ping data packets are transmitted.

Namespace:   System.Net.NetworkInformation
Assembly:  System (in System.dll)


public class PingOptions


Initializes a new instance of the PingOptions class.

System_CAPS_pubmethodPingOptions(Int32, Boolean)

Initializes a new instance of the PingOptions class and sets the Time to Live and fragmentation values.


Gets or sets a Boolean value that controls fragmentation of the data sent to the remote host.


Gets or sets the number of routing nodes that can forward the Ping data before it is discarded.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

The PingOptions class provides the Ttl and DontFragment properties to control how Internet Control Message Protocol (ICMP) echo request packets are transmitted.

The Ttl property specifies the Time to Live for packets sent by the Ping class. This value indicates the number of routing nodes that can forward a Ping packet before it is discarded. Setting this option is useful if you want to test the number of forwards, also known as hops, are required to send a packet from a source computer to a destination computer.

The DontFragment property controls whether data sent to a remote host can be divided into multiple packets. This option is useful if you want to test the maximum transmission unit (MTU) of the routers and gateways used to transmit the packet.

Instances of the PingOptions class are passed to the Send and SendAsync methods, and the PingReply class returns instances of PingOptions via the Options property.

For a list of initial property values for an instance of PingOptions, see the PingOptions constructor.

The following code example uses the Ping, PingOptions and PingReply classes to send an ICMP echo request to the host specified on the command line.

using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

namespace Examples.System.Net.NetworkInformation.PingTest
    public class PingExample
        // 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;
            PingReply reply = pingSender.Send (args[0], timeout, buffer, options);
            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);

.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft