PingReply.Address 属性

定义

获取发送 Internet 控制消息协议 (ICMP) 回送答复的主机地址。

public:
 property System::Net::IPAddress ^ Address { System::Net::IPAddress ^ get(); };
public System.Net.IPAddress Address { get; }
member this.Address : System.Net.IPAddress
Public ReadOnly Property Address As IPAddress

属性值

包含 ICMP 回送消息目标的 IPAddress

示例

下面的代码示例以同步方式发送 ICMP 回显请求,并显示此属性的值。

void SimplePing()
{
   Ping ^ pingSender = gcnew Ping;
   PingReply ^ reply = pingSender->Send( "www.contoso.com" );
   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 );
   }
   else
   {
      Console::WriteLine( reply->Status );
   }
}
public static void SimplePing ()
{
    Ping pingSender = new Ping ();
    PingReply reply = pingSender.Send ("www.contoso.com");

    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);
    }
    else
    {
        Console.WriteLine (reply.Status);
    }
}

注解

Address任何重载返回的 Send 都可能源自恶意远程计算机。 请勿使用此地址连接到远程计算机。 使用 DNS 确定要连接到的计算机的 IP 地址。

适用于