PingReply.Address Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the address of the host that sends the Internet Control Message Protocol (ICMP) echo reply.

Namespace:   System.Net.NetworkInformation
Assembly:  System (in System.dll)

public IPAddress Address { get; }

Property Value

Type: System.Net.IPAddress

An IPAddress containing the destination for the ICMP echo message.

The Address returned by any of the Send overloads can originate from a malicious remote computer. Do not connect to the remote computer using this address. Use DNS to determine the IP address of the machine to which you want to connect.

The following code example sends an ICMP echo request synchronously and displays the value of this property.

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);
    }
}

.NET Framework
Available since 2.0
Return to top
Show: