PingOptions Class
Used to control how Ping data packets are transmitted.
Assembly: System (in System.dll)
| Name | Description | |
|---|---|---|
![]() | PingOptions() | Initializes a new instance of the PingOptions class. |
![]() | PingOptions(Int32, Boolean) | Initializes a new instance of the PingOptions class and sets the Time to Live and fragmentation values. |
| Name | Description | |
|---|---|---|
![]() | DontFragment | Gets or sets a Boolean value that controls fragmentation of the data sent to the remote host. |
![]() | Ttl | Gets or sets the number of routing nodes that can forward the Ping data before it is discarded. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() | 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.dll> using namespace System; using namespace System::Net; using namespace System::Net::NetworkInformation; using namespace System::Text; // args[1] can be an IPaddress or host name. int main() { array<String^>^args = Environment::GetCommandLineArgs(); Ping ^ pingSender = gcnew Ping; PingOptions ^ options = gcnew 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"; array<Byte>^buffer = Encoding::ASCII->GetBytes( data ); int timeout = 120; PingReply ^ reply = pingSender->Send( args[ 1 ], 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 ); } }
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.


