PingReply.Status Свойство


Возвращает состояние попытки отправки запроса проверки связи ICMP и получения соответствующего сообщения ответа проверки связи ICMP.Gets the status of an attempt to send an Internet Control Message Protocol (ICMP) echo request and receive the corresponding ICMP echo reply message.

 property System::Net::NetworkInformation::IPStatus Status { System::Net::NetworkInformation::IPStatus get(); };
public System.Net.NetworkInformation.IPStatus Status { get; }
member this.Status : System.Net.NetworkInformation.IPStatus
Public ReadOnly Property Status As IPStatus

Значение свойства

Значение IPStatus, показывающее результат запроса.An IPStatus value indicating the result of the request.


В следующем примере кода показано использование класса Ping для синхронной отправки запроса проверки связи ICMP и отображения ответа.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 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);


Если значение Status не Success, не следует использовать значения, возвращаемые свойствами RoundtripTime, Options или Buffer.If the value of Status is not Success, you should not use the values returned by the RoundtripTime, Options or Buffer properties. Свойства RoundtripTime и Buffer будут возвращать ноль, а свойство Options будет возвращать null.The RoundtripTime and Buffer properties will return zero, and the Options property will return null.

Применяется к