PingOptions Classe

Definizione

Utilizzato per controllare come vengono trasmessi i pacchetti di dati Ping.

public ref class PingOptions
public class PingOptions
type PingOptions = class
Public Class PingOptions
Ereditarietà
PingOptions

Esempio

Nell'esempio di codice seguente vengono usate le PingPingOptions classi e PingReply per inviare una richiesta echo ICMP all'host specificato nella riga di comando.

#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);
            }
        }
    }
}
open System.Net.NetworkInformation
open System.Text

// args[0] can be an IPaddress or host name.
[<EntryPoint>]
let main args =
    let pingSender = new Ping()

    // Use the default Ttl value which is 128,
    // but change the fragmentation behavior.
    let options = PingOptions()
    options.DontFragment <- true

    // Create a buffer of 32 bytes of data to be transmitted.
    let data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    let buffer = Encoding.ASCII.GetBytes data
    let timeout = 120
    let reply: PingReply = pingSender.Send(args.[0], timeout, buffer, options)

    match reply.Status with
    | IPStatus.Success ->
        printfn "Address: %O" reply.Address
        printfn "RoundTrip time: %d" reply.RoundtripTime
        printfn "Time to live: %d" reply.Options.Ttl
        printfn "Don't fragment: %b" reply.Options.DontFragment
        printfn "Buffer size: %d" reply.Buffer.Length
        0
    | _ ->
        eprintfn "Error sending ping: %O" reply
        eprintfn "Error was: %O" reply.Status
        1

Commenti

La PingOptions classe fornisce le proprietà e DontFragment per controllare il Ttl modo in cui vengono trasmessi i pacchetti di richieste echo di Internet Control Message Protocol (ICMP).

La Ttl proprietà specifica il valore Time to Live per i pacchetti inviati dalla Ping classe . Questo valore indica il numero di nodi di routing che possono inoltrare un Ping pacchetto prima che venga rimosso. L'impostazione di questa opzione è utile se si vuole testare il numero di inoltro, noto anche come hop, è necessario inviare un pacchetto da un computer di origine a un computer di destinazione.

La proprietà controlla se i DontFragment dati inviati a un host remoto possono essere suddivisi in più pacchetti. Questa opzione è utile se si vuole testare l'unità di trasmissione massima (MTU) dei router e dei gateway usati per trasmettere il pacchetto.

Le istanze della PingOptions classe vengono passate ai Send metodi e SendAsync e la PingReply classe restituisce istanze di PingOptions tramite la Options proprietà .

Per un elenco di valori di proprietà iniziali per un'istanza di PingOptions, vedere il PingOptions costruttore.

Costruttori

PingOptions()

Inizializza una nuova istanza della classe PingOptions.

PingOptions(Int32, Boolean)

Inizializza una nuova istanza della classe PingOptions e imposta i valori TTL (Time to Live) e frammentazione.

Proprietà

DontFragment

Ottiene o imposta un valore Boolean che controlla la frammentazione dei dati inviati all'host remoto.

Ttl

Ottiene o imposta il numero di nodi di routing che possono inoltrare i dati di Ping prima che vengano eliminati.

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a