PingReply Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
public ref class PingReply
public class PingReply
type PingReply = class
Public Class PingReply
- Ereditarietà
-
PingReply
Esempio
L'esempio di codice seguente illustra l'uso Ping della classe per inviare una richiesta echo ICMP in modo sincrono e visualizzare la risposta.
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 Ping classe tenta di inviare una richiesta echo ICMP (Internet Control Message Protocol) a un computer remoto e di ricevere informazioni dal computer tramite un messaggio di risposta echo ICMP. La Ping classe usa istanze della PingReply classe per restituire informazioni sull'operazione, ad esempio il relativo stato e il tempo impiegato per inviare la richiesta e ricevere la risposta.
I Send metodi restituiscono direttamente le istanze della PingReply classe . I SendAsync metodi restituiscono un PingReply oggetto nel PingCompletedEventHandler parametro del PingCompletedEventArgs metodo. L'oggetto PingReply è accessibile tramite la Reply proprietà .
Se il valore di Status non è , non è consigliabile usare i valori restituiti dalle RoundtripTimeproprietà o BufferOptions .Success La RoundtripTime proprietà restituirà zero, la Buffer proprietà restituirà una matrice vuota e la Options proprietà restituirà null.
Proprietà
| Nome | Descrizione |
|---|---|
| Address |
Ottiene l'indirizzo dell'host che invia la riposta echo del protocollo ICMP. |
| Buffer |
Ottiene il buffer dei dati ricevuti in un messaggio di risposta echo del protocollo ICMP. |
| Options |
Ottiene le opzioni utilizzate per trasmettere la risposta a una richiesta echo del protocollo ICMP. |
| RoundtripTime |
Ottiene il numero di millisecondi impiegati per inviare una richiesta echo ICMP (Internet Control Message Protocol) e per ricevere il messaggio di risposta echo ICMP corrispondente. |
| Status |
Ottiene lo stato di un tentativo di inviare una richiesta echo del protocollo ICMP e ricevere il rispettivo messaggio di risposta echo del protocollo ICMP. |
Metodi
| Nome | Descrizione |
|---|---|
| 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) |