PingOptions PingOptions PingOptions PingOptions Class

Definición

Se utiliza para controlar el modo en que se transmiten los paquetes de datos Ping.Used to control how Ping data packets are transmitted.

public ref class PingOptions
public class PingOptions
type PingOptions = class
Public Class PingOptions
Herencia
PingOptionsPingOptionsPingOptionsPingOptions

Ejemplos

En el ejemplo de código siguiente Pingse PingOptions usan PingReply las clases, y para enviar una solicitud de eco ICMP al host especificado en la línea de comandos.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 );
   }

   
}

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);
            }
        }
    }
}

Comentarios

La PingOptions clase proporciona las Ttl propiedades DontFragment y para controlar cómo se transmiten los paquetes de solicitud de eco del Protocolo de mensajes de control de Internet (ICMP).The PingOptions class provides the Ttl and DontFragment properties to control how Internet Control Message Protocol (ICMP) echo request packets are transmitted.

La Ttl propiedad especifica el período de vida de los paquetes enviados por la Ping clase.The Ttl property specifies the Time to Live for packets sent by the Ping class. Este valor indica el número de nodos de enrutamiento que pueden reenviar un paquete antes de Ping que se descarte.This value indicates the number of routing nodes that can forward a Ping packet before it is discarded. La configuración de esta opción es útil si desea probar el número de reenvíos, también conocidos como saltos, para enviar un paquete desde un equipo de origen a un equipo de destino.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.

La DontFragment propiedad controla si los datos enviados a un host remoto se pueden dividir en varios paquetes.The DontFragment property controls whether data sent to a remote host can be divided into multiple packets. Esta opción es útil si desea probar la unidad de transmisión máxima (MTU) de los enrutadores y las puertas de enlace que se usan para transmitir el paquete.This option is useful if you want to test the maximum transmission unit (MTU) of the routers and gateways used to transmit the packet.

Las instancias de PingOptions la clase se pasan a Send los SendAsync métodos y, y PingReply la clase devuelve instancias PingOptions de a Options través de la propiedad.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.

Para obtener una lista de los valores de propiedad iniciales de PingOptionsuna instancia de PingOptions , vea el constructor.For a list of initial property values for an instance of PingOptions, see the PingOptions constructor.

Constructores

PingOptions() PingOptions() PingOptions() PingOptions()

Inicializa una nueva instancia de la clase PingOptions.Initializes a new instance of the PingOptions class.

PingOptions(Int32, Boolean) PingOptions(Int32, Boolean) PingOptions(Int32, Boolean) PingOptions(Int32, Boolean)

Inicializa una nueva instancia de la clase PingOptions y establece los valores de período de vida y fragmentación.Initializes a new instance of the PingOptions class and sets the Time to Live and fragmentation values.

Propiedades

DontFragment DontFragment DontFragment DontFragment

Obtiene o establece un valor Boolean que controla la fragmentación de los datos enviados al host remoto.Gets or sets a Boolean value that controls fragmentation of the data sent to the remote host.

Ttl Ttl Ttl Ttl

Obtiene o establece el número de nodos de enrutamiento que pueden reenviar los datos Ping antes de que se descarten.Gets or sets the number of routing nodes that can forward the Ping data before it is discarded.

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Se aplica a