PingReply.Status Propriedade
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém o status de uma tentativa de enviar uma solicitação de eco do protocolo ICMP e receber a mensagem de resposta de eco ICMP correspondente.
public:
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
Um valor IPStatus que indica o resultado da solicitação.
O exemplo de código a seguir demonstra o uso Ping da classe para enviar uma solicitação de eco ICMP de forma síncrona e exibir a resposta.
#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);
}
}
}
}
open System.Net.NetworkInformation
open System.Text
// args[0] can be an IPaddress or host name.
[<EntryPoint>]
let main args =
let pingSender = new Ping()
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
let options = PingOptions()
options.DontFragment <- true
// Create a buffer of 32 bytes of data to be transmitted.
let data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
let buffer = Encoding.ASCII.GetBytes data
let timeout = 120
let reply: PingReply = pingSender.Send(args.[0], timeout, buffer, options)
match reply.Status with
| IPStatus.Success ->
printfn "Address: %O" reply.Address
printfn "RoundTrip time: %d" reply.RoundtripTime
printfn "Time to live: %d" reply.Options.Ttl
printfn "Don't fragment: %b" reply.Options.DontFragment
printfn "Buffer size: %d" reply.Buffer.Length
0
| _ ->
eprintfn "Error sending ping: %O" reply
eprintfn "Error was: %O" reply.Status
1
Se o valor de Status não for , você não deverá usar os valores retornados pelas RoundtripTimepropriedades ou OptionsBuffer .Success As RoundtripTime propriedades e Buffer retornarão zero e a Options propriedade retornará null
.
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: