PingReply Classe

Définition

Fournit des informations sur l'état et les données résultant d'une opération Send ou SendAsync.

public ref class PingReply
public class PingReply
type PingReply = class
Public Class PingReply
Héritage
PingReply

Exemples

L’exemple de code suivant illustre l’utilisation de Ping la classe pour envoyer une demande d’écho ICMP de manière synchrone et afficher la réponse.

#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

Remarques

La Ping classe tente d’envoyer une demande d’écho ICMP (Internet Control Message Protocol) à un ordinateur distant et de recevoir des informations de l’ordinateur via un message de réponse d’écho ICMP. La Ping classe utilise des instances de la PingReply classe pour retourner des informations sur l’opération, telles que son état et le temps nécessaire pour envoyer la demande et recevoir la réponse.

Les Send méthodes retournent directement les instances de la PingReply classe. Les SendAsync méthodes retournent un PingReply dans le paramètre de la PingCompletedEventHandlerPingCompletedEventArgs méthode. Le PingReply est accessible via la Reply propriété .

Si la valeur de Status n’est pas Success, vous ne devez pas utiliser les valeurs retournées par les RoundtripTimepropriétés ou OptionsBuffer . La RoundtripTime propriété retourne zéro, la Buffer propriété renvoie un tableau vide et la Options propriété retourne null.

Propriétés

Address

Obtient l'adresse de l'hôte qui envoie la réponse à écho ICMP.

Buffer

Obtient la mémoire tampon des données reçues dans un message de réponse à écho ICMP.

Options

Obtient les options utilisées pour transmettre la réponse à une demande d'écho ICMP.

RoundtripTime

Obtient le nombre de millisecondes que prennent l’envoi d’une demande d’écho ICMP (Internet Control Message Protocol) et la réception du message de réponse d’écho ICMP correspondant.

Status

Obtient l'état d'une tentative d'envoi de demande d'écho ICMP et de réception du message ICMP de réponse à écho correspondant.

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à