Ping 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
允许应用程序确定是否可通过网络访问远程计算机。
public ref class Ping : System::ComponentModel::Componentpublic ref class Ping : IDisposablepublic ref class Ping : System::ComponentModel::Component, IDisposablepublic class Ping : System.ComponentModel.Componentpublic class Ping : IDisposablepublic class Ping : System.ComponentModel.Component, IDisposabletype Ping = class
    inherit Componenttype Ping = class
    interface IDisposabletype Ping = class
    inherit Component
    interface IDisposablePublic Class Ping
Inherits ComponentPublic Class Ping
Implements IDisposablePublic Class Ping
Inherits Component
Implements IDisposable- 继承
- 继承
- 
				Ping
- 实现
示例
下面的代码示例演示如何同步使用 Ping 类。
#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 类。
#using <System.dll>
using namespace System;
using namespace System::Text;
using namespace System::Net;
using namespace System::Net::NetworkInformation;
using namespace System::ComponentModel;
using namespace System::Threading;
void PingCompletedCallback( Object^ sender, PingCompletedEventArgs^ e );
void DisplayReply( PingReply^ reply );
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   if ( args->Length == 1 )
      throw gcnew ArgumentException( "Ping needs a host or IP Address." );
   String^ who = args[ 1 ];
   AutoResetEvent^ waiter = gcnew AutoResetEvent( false );
   
   Ping ^ pingSender = gcnew Ping;
   
   // When the PingCompleted event is raised,
   // the PingCompletedCallback method is called.
   pingSender->PingCompleted += gcnew PingCompletedEventHandler( PingCompletedCallback );
   
   // Create a buffer of 32 bytes of data to be transmitted.
   String^ data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
   array<Byte>^buffer = Encoding::ASCII->GetBytes( data );
   
   // Wait 12 seconds for a reply.
   int timeout = 12000;
   
   // Set options for transmission:
   // The data can go through 64 gateways or routers
   // before it is destroyed, and the data packet
   // cannot be fragmented.
   PingOptions ^ options = gcnew PingOptions( 64,true );
   Console::WriteLine( "Time to live: {0}", options->Ttl );
   Console::WriteLine( "Don't fragment: {0}", options->DontFragment );
   
   // Send the ping asynchronously.
   // Use the waiter as the user token.
   // When the callback completes, it can wake up this thread.
   pingSender->SendAsync( who, timeout, buffer, options, waiter );
   
   // Prevent this example application from ending.
   // A real application should do something useful
   // when possible.
   waiter->WaitOne();
   Console::WriteLine( "Ping example completed." );
}
void PingCompletedCallback( Object^ /*sender*/, PingCompletedEventArgs^ e )
{
   
   // If the operation was canceled, display a message to the user.
   if ( e->Cancelled )
   {
      Console::WriteLine( "Ping canceled." );
      
      // Let the main thread resume. 
      // UserToken is the AutoResetEvent object that the main thread 
      // is waiting for.
      (dynamic_cast<AutoResetEvent^>(e->UserState))->Set();
   }
   
   // If an error occurred, display the exception to the user.
   if ( e->Error != nullptr )
   {
      Console::WriteLine( "Ping failed:" );
      Console::WriteLine( e->Error->ToString() );
      
      // Let the main thread resume. 
      (dynamic_cast<AutoResetEvent^>(e->UserState))->Set();
   }
   PingReply ^ reply = e->Reply;
   DisplayReply( reply );
   
   // Let the main thread resume.
   (dynamic_cast<AutoResetEvent^>(e->UserState))->Set();
}
void DisplayReply( PingReply ^ reply )
{
   if ( reply == nullptr )
      return;
   Console::WriteLine( "ping status: {0}", reply->Status );
   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.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.ComponentModel;
using System.Threading;
namespace Examples.System.Net.NetworkInformation.PingTest
{
    public class PingExample
    {
        public static void Main (string[] args)
        {
            if (args.Length == 0)
                throw new ArgumentException ("Ping needs a host or IP Address.");
            string who = args[0];
            AutoResetEvent waiter = new AutoResetEvent (false);
            Ping pingSender = new Ping ();
            // When the PingCompleted event is raised,
            // the PingCompletedCallback method is called.
            pingSender.PingCompleted += new PingCompletedEventHandler (PingCompletedCallback);
            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes (data);
            // Wait 12 seconds for a reply.
            int timeout = 12000;
            // Set options for transmission:
            // The data can go through 64 gateways or routers
            // before it is destroyed, and the data packet
            // cannot be fragmented.
            PingOptions options = new PingOptions (64, true);
            Console.WriteLine ("Time to live: {0}", options.Ttl);
            Console.WriteLine ("Don't fragment: {0}", options.DontFragment);
            // Send the ping asynchronously.
            // Use the waiter as the user token.
            // When the callback completes, it can wake up this thread.
            pingSender.SendAsync(who, timeout, buffer, options, waiter);
            // Prevent this example application from ending.
            // A real application should do something useful
            // when possible.
            waiter.WaitOne ();
            Console.WriteLine ("Ping example completed.");
        }
        private static void PingCompletedCallback (object sender, PingCompletedEventArgs e)
        {
            // If the operation was canceled, display a message to the user.
            if (e.Cancelled)
            {
                Console.WriteLine ("Ping canceled.");
                // Let the main thread resume.
                // UserToken is the AutoResetEvent object that the main thread
                // is waiting for.
                ((AutoResetEvent)e.UserState).Set ();
            }
            // If an error occurred, display the exception to the user.
            if (e.Error != null)
            {
                Console.WriteLine ("Ping failed:");
                Console.WriteLine (e.Error.ToString ());
                // Let the main thread resume.
                ((AutoResetEvent)e.UserState).Set();
            }
            PingReply reply = e.Reply;
            DisplayReply (reply);
            // Let the main thread resume.
            ((AutoResetEvent)e.UserState).Set();
        }
        public static void DisplayReply (PingReply reply)
        {
            if (reply == null)
                return;
            Console.WriteLine ("ping status: {0}", reply.Status);
            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);
            }
        }
    }
}
注解
应用程序使用 Ping 类来检测远程计算机是否可访问。
网络拓扑可以确定是否 Ping 可以成功联系远程主机。 代理、网络地址转换 (NAT) 设备或防火墙的存在和配置可能会阻止 Ping 成功。 成功 Ping 仅表示可以在网络上访问远程主机;无法保证远程主机上存在更高级别的服务 (,例如 Web 服务器) 。
此类提供的功能类似于 Ping.exe 命令行工具。 Send和 SendAsync 方法将 Internet 控制消息协议 (ICMP) 回显请求消息发送到远程计算机,并等待来自该计算机的 ICMP 回送答复消息。 有关 ICMP 消息的详细说明,请参阅 RFC 792,可从 https://www.ietf.org获取。
以下类型与 类一起使用 Ping ,下面详细介绍了这些类型。
| 类型名称 | 说明 | 
|---|---|
| IPStatus | 定义描述 ICMP 回送请求消息结果的状态代码。 | 
| PingOptions | 允许配置或检索设置,这些设置控制 () 转发 Ttl 请求数据包的次数,以及是否可以将其分段 (DontFragment ) 。 | 
| PingReply | 包含 ICMP 回显请求的结果。 | 
| PingException | 如果发生不可恢复的错误,则引发。 | 
| PingCompletedEventArgs | 包含与 PingCompleted 事件关联的数据,这些事件在调用完成或取消时 SendAsync 引发。 | 
| PingCompletedEventHandler | 提供调用完成或取消时 SendAsync 调用的回调方法的委托。 | 
Send和 SendAsync 方法在 对象中PingReply返回答复。 属性 PingReply.Status 返回一个 IPStatus 值来指示请求的结果。
发送请求时,必须指定远程计算机。 可以通过提供主机名字符串、字符串格式的 IP 地址或 IPAddress 对象来执行此操作。
还可以指定以下任一类型的信息:
- 请求附带的数据。 通过 - buffer指定,可以了解特定大小的数据包往返远程主机所需的时间,以及网络路径的最大传输单元。 (请参阅Send采用参数的- buffer或 SendAsync 重载。)
- ICMP Echo 数据包是否可以在传输中分段。 (请参阅 DontFragment 采用参数的属性和 Send 或 SendAsync 重载 - options。)
- 路由节点(如路由器或网关)在数据包到达目标计算机或被丢弃之前可以转发的次数。 (请参阅 Ttl 和 Send 采用参数的 - options或 SendAsync 重载。)
类 Ping 提供用于发送请求的同步和异步方法。 如果应用程序在等待回复时应阻止,请使用 Send 方法;这些方法是同步的。 如果应用程序不应阻止,请使用异步 SendAsync 方法。 对 的 SendAsync 调用在其自己的线程中执行,该线程从线程池自动分配。 异步操作完成后,会引发 PingCompleted 事件。 应用程序使用 PingCompletedEventHandler 委托来指定为 PingCompleted 事件调用的方法。 在调用 SendAsync之前,必须将委托添加到 PingCompletedEventHandler 事件。 委托的 方法接收一个 PingCompletedEventArgs 对象,该对象包含 PingReply 描述调用结果的对象 SendAsync 。
不能使用 类的 Ping 同一实例来生成多个同时的 ICMP Echo 请求。 在调用 Send 正在进行时 SendAsync 调用或在完成所有以前的调用之前多次调用 SendAsync 会导致 InvalidOperationException。
构造函数
| Ping() | 初始化 Ping 类的新实例。 | 
属性
| CanRaiseEvents | 获取一个指示组件是否可以引发事件的值。(继承自 Component) | 
| Container | 获取包含 IContainer 的 Component。(继承自 Component) | 
| DesignMode | 获取一个值,用以指示 Component 当前是否处于设计模式。(继承自 Component) | 
| Events | 获取附加到此 Component 的事件处理程序的列表。(继承自 Component) | 
| Site | (继承自 Component) | 
方法
| CreateObjRef(Type) | 创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。(继承自 MarshalByRefObject) | 
| Dispose() | 释放由 Ping 使用的非托管资源和托管资源。 | 
| Dispose() | 释放由 Component 使用的所有资源。(继承自 Component) | 
| Dispose(Boolean) | 释放由 Ping 对象使用的非托管资源,并可根据需要释放托管资源。 | 
| Dispose(Boolean) | 释放由 Component 占用的非托管资源,还可以另外再释放托管资源。(继承自 Component) | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetLifetimeService() | 
		已过时.
	 检索控制此实例的生存期策略的当前生存期服务对象。(继承自 MarshalByRefObject) | 
| GetService(Type) | 返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。(继承自 Component) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| InitializeLifetimeService() | 
		已过时.
	 获取生存期服务对象来控制此实例的生存期策略。(继承自 MarshalByRefObject) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| MemberwiseClone(Boolean) | 创建当前 MarshalByRefObject 对象的浅表副本。(继承自 MarshalByRefObject) | 
| OnPingCompleted(PingCompletedEventArgs) | 引发 PingCompleted 事件。 | 
| Send(IPAddress) | 尝试将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送答复消息。 | 
| Send(IPAddress, Int32) | 尝试将包含指定数据缓冲区的 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送应答消息。 使用此方法可以为操作指定一个超时值。 | 
| Send(IPAddress, Int32, Byte[]) | 尝试将包含指定数据缓冲区的 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送应答消息。 此重载使您可以为操作指定一个超时值。 | 
| Send(IPAddress, Int32, Byte[], PingOptions) | 尝试将包含指定数据缓冲区的 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送答复消息。 此重载允许您指定操作的超时值,并控制 ICMP 回显消息数据包的碎片和生存时间值。 | 
| Send(IPAddress, TimeSpan, Byte[], PingOptions) | 尝试将 Internet 控制消息协议 (ICMP) 回显消息发送到具有指定 IPAddress的计算机,并从该计算机接收相应的 ICMP 回送答复消息。 | 
| Send(String) | 尝试向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。 | 
| Send(String, Int32) | 尝试向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。 使用此方法可以为操作指定一个超时值。 | 
| Send(String, Int32, Byte[]) | 尝试用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,然后从该计算机接收对应的 ICMP 回显回复消息。 此重载使您可以为操作指定一个超时值。 | 
| Send(String, Int32, Byte[], PingOptions) | 尝试用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,然后从该计算机接收对应的 ICMP 回显回复消息。 此重载允许您指定操作的超时值,并控制 ICMP 数据包的碎片和生存时间值。 | 
| Send(String, TimeSpan, Byte[], PingOptions) | 尝试将 Internet 控制消息协议 (ICMP) 回显消息发送到指定的计算机,并从该计算机接收相应的 ICMP 回送答复消息。 | 
| SendAsync(IPAddress, Int32, Byte[], Object) | 尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回显回复消息。 此重载使您可以为操作指定一个超时值。 | 
| SendAsync(IPAddress, Int32, Byte[], PingOptions, Object) | 尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回显回复消息。 此重载允许您指定操作的超时值,并控制 ICMP 回显消息数据包的碎片和生存时间值。 | 
| SendAsync(IPAddress, Int32, Object) | 尝试以异步方式向指定 IPAddress 的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。 此重载使您可以为操作指定一个超时值。 | 
| SendAsync(IPAddress, Object) | 尝试以异步方式向指定 IPAddress 的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。 | 
| SendAsync(String, Int32, Byte[], Object) | 尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,并从该计算机接收对应的 ICMP 回显回复消息。 此重载使您可以为操作指定一个超时值。 | 
| SendAsync(String, Int32, Byte[], PingOptions, Object) | 尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,并从该计算机接收对应的 ICMP 回显回复消息。 此重载允许您指定操作的超时值,并控制 ICMP 数据包的碎片和生存时间值。 | 
| SendAsync(String, Int32, Object) | 尝试以异步方式向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。 此重载使您可以为操作指定一个超时值。 | 
| SendAsync(String, Object) | 尝试以异步方式向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。 | 
| SendAsyncCancel() | 取消所有挂起的发送 Internet 控制消息协议 (ICMP) 回送消息并接收相应 ICMP 回送答复消息的异步请求。 | 
| SendPingAsync(IPAddress) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 | 
| SendPingAsync(IPAddress, Int32) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 此重载使您可以为操作指定一个超时值。 | 
| SendPingAsync(IPAddress, Int32, Byte[]) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 此重载将允许您为操作指定超时值并指定用于发送和接收的缓冲区。 | 
| SendPingAsync(IPAddress, Int32, Byte[], PingOptions) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 利用此重载,您可以指定操作的超时值和用于进行发送和接收的缓冲区,并可以控制 ICMP 回送消息数据包的碎片和生存时间值。 | 
| SendPingAsync(IPAddress, TimeSpan, Byte[], PingOptions, CancellationToken) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 此重载允许指定操作的超时值、用于发送和接收的缓冲区、控制碎片和生存时间值以及 CancellationToken ICMP 回送消息数据包的 。 | 
| SendPingAsync(String) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 | 
| SendPingAsync(String, Int32) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 此重载使您可以为操作指定一个超时值。 | 
| SendPingAsync(String, Int32, Byte[]) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 此重载将允许您为操作指定超时值并指定用于发送和接收的缓冲区。 | 
| SendPingAsync(String, Int32, Byte[], PingOptions) | 使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。 利用此重载,您可以指定操作的超时值和用于进行发送和接收的缓冲区,并可以控制 ICMP 回送消息数据包的碎片和生存时间值。 | 
| SendPingAsync(String, TimeSpan, Byte[], PingOptions, CancellationToken) | 将 Internet 控制消息协议 (ICMP) 具有指定数据缓冲区的回显消息发送到指定计算机,并从该计算机接收相应的 ICMP 回送答复消息作为异步操作。 此重载允许指定操作的超时值、用于发送和接收的缓冲区、控制碎片和生存时间值以及 CancellationToken ICMP 回送消息数据包的 。 | 
| ToString() | 返回包含 Component 的名称的 String(如果有)。 不应重写此方法。(继承自 Component) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
事件
| Disposed | 在通过调用 Dispose() 方法释放组件时发生。(继承自 Component) | 
| PingCompleted | 当发送 Internet 控制消息协议 (ICMP) 回送消息并接收相应 ICMP 回送答复消息的异步操作完成或被取消时发生。 | 
显式接口实现
| IDisposable.Dispose() | 释放由 Ping 类的实例使用的所有资源。 |