PingOptions 클래스

정의

Ping 데이터 패킷의 전송 방법을 제어하는 데 사용됩니다.

public ref class PingOptions
public class PingOptions
type PingOptions = class
Public Class PingOptions
상속
PingOptions

예제

다음 코드 예제에서는 , PingOptionsPingReply 클래스를 사용하여 Ping명령줄에 지정된 호스트에 ICMP 에코 요청을 보냅니다.

#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

설명

클래스는 PingOptionsDontFragment 속성을 제공하여 Ttl ICMP(Internet Control Message Protocol) 에코 요청 패킷이 전송되는 방식을 제어합니다.

속성은 Ttl 클래스에서 보낸 패킷의 TL(Time to Live)을 Ping 지정합니다. 이 값은 삭제되기 전에 패킷을 전달할 Ping 수 있는 라우팅 노드 수를 나타냅니다. 이 옵션을 설정하면 원본 컴퓨터에서 대상 컴퓨터로 패킷을 보내는 데 필요한 전달 횟수(홉이라고도 함)를 테스트하려는 경우에 유용합니다.

속성은 DontFragment 원격 호스트로 전송된 데이터를 여러 패킷으로 나눌 수 있는지 여부를 제어합니다. 이 옵션은 패킷을 전송하는 데 사용되는 라우터 및 게이트웨이의 MTU(최대 전송 단위)를 테스트하려는 경우에 유용합니다.

인스턴스의 PingOptions 클래스에 전달 Send 됩니다는 및 SendAsync 메서드 및 PingReply 클래스를 통해 인스턴스 PingOptions 를 반환 합니다 Options 속성입니다.

인스턴스의 초기 속성 값의 목록을 PingOptions, 참조는 PingOptions 생성자입니다.

생성자

PingOptions()

PingOptions 클래스의 새 인스턴스를 초기화합니다.

PingOptions(Int32, Boolean)

PingOptions 클래스의 새 인스턴스를 초기화하고 Time to Live 및 조각화 값을 설정합니다.

속성

DontFragment

원격 호스트로 보낼 데이터의 조각화를 제어하는 Boolean 값을 가져오거나 설정합니다.

Ttl

Ping 데이터가 삭제되기 전에 이 데이터를 전달할 수 있는 라우팅 노드의 수를 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상