Export (0) Print
Expand All

PingReply::Status Property

Gets the status of an attempt to send an Internet Control Message Protocol (ICMP) echo request and receive the corresponding ICMP echo reply message.

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

public:
property IPStatus Status {
	IPStatus get ();
}

Property Value

Type: System.Net.NetworkInformation::IPStatus
An IPStatus value indicating the result of the request.

If the value of Status is not Success, you should not use the values returned by the RoundtripTime, Options or Buffer properties. The RoundtripTime and Buffer properties will return zero, and the Options property will return nullptr.

The following code example demonstrates using Ping class to send an ICMP echo request synchronously and display the response.

#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 <mscorlib.dll>
#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 ()
{
    String* args[] = Environment::GetCommandLineArgs();

    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 = S"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    Byte buffer[] = Encoding::ASCII->GetBytes (data);
    int timeout = 120;
    PingReply* reply = pingSender->Send (args[1], buffer, timeout, options);
    if (reply->Status == IPStatus::Success)
    {
        Console::WriteLine (S"Address: {0}", reply->Address->ToString ());
        Console::WriteLine (S"RoundTrip time: {0}", __box(reply->RoundTripTime));
        Console::WriteLine (S"Time to live: {0}", __box(reply->Options->Ttl));
        Console::WriteLine (S"Don't fragment: {0}", __box(reply->Options->DontFragment));
        Console::WriteLine (S"Buffer size: {0}", __box(reply->Buffer->Length));
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft