PingReply.Address 属性

定义

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

public System.Net.IPAddress Address { get; }

属性值

包含 ICMP 回送消息目标的 IPAddress

示例

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

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 地址。

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1