共用方式為


PingReply 類別

定義

提供由於 SendSendAsync 作業而產生的狀態和資料等相關資訊。

public ref class PingReply
public class PingReply
type PingReply = class
Public Class PingReply
繼承
PingReply

範例

下列程式代碼範例示範如何使用 Ping 類別同步傳送ICMP回應要求,並顯示回應。

#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

備註

類別 Ping 會嘗試將因特網控制訊息通訊協定 (ICMP) 回應要求傳送至遠端電腦,並透過ICMP回應回覆訊息從電腦接收資訊。 類別 Ping 使用 類別的 PingReply 實例來傳回作業的相關信息,例如其狀態和傳送要求並接收回復所花費的時間。

方法 Send 會直接傳回 類別的 PingReply 實例。 方法SendAsync會在方法的 PingCompletedEventArgs 參數中PingCompletedEventHandler傳回 PingReply 。 透過 PingReply 屬性存取 Reply

如果 的值Status不是 Success,您就不應該使用、 OptionsBuffer 屬性所RoundtripTime傳回的值。 屬性 RoundtripTime 會傳回零, Buffer 屬性會傳回空數組,而 Options 屬性會傳回 null

屬性

Address

取得主機位址,該主機傳送網際網路控制訊息通訊協定 (ICMP) 回應回覆。

Buffer

取得在網際網路控制訊息通訊協定 (ICMP) 回應回覆訊息中所收到的資料緩衝區。

Options

取得選項,用於傳送對網際網路控制訊息通訊協定 (ICMP) 回應要求的回覆。

RoundtripTime

取得用於傳送網際網路控制訊息通訊協定 (ICMP) 回應要求及接收對應的 ICMP 回應回覆訊息的毫秒數。

Status

取得嘗試傳送網際網路控制訊息通訊協定 (ICMP) 回應要求及接收對應的 ICMP 回應回覆訊息的狀態。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於