PingOptions 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
用于控制如何传输 Ping 数据包。
public ref class PingOptions
	public class PingOptions
	type PingOptions = class
	Public Class PingOptions
		- 继承
 - 
				PingOptions
 
示例
下面的代码示例使用 Ping和 PingOptionsPingReply 类将 ICMP 回显请求发送到命令行中指定的主机。
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
	注解
类 PingOptions 提供 Ttl 和 DontFragment 属性来控制 Internet 控制消息协议 (ICMP) 回显请求数据包的传输方式。
属性 Ttl 指定 类发送的数据包的 Ping 生存时间。 此值指示在丢弃数据包之前可以转发 Ping 数据包的路由节点数。 如果要测试转发数(也称为跃点)才能将数据包从源计算机发送到目标计算机,则设置此选项非常有用。
属性 DontFragment 控制发送到远程主机的数据是否可以划分为多个数据包。 如果要测试用于传输数据包的路由器和网关 (MTU) 的最大传输单元,此选项非常有用。
类的PingOptions实例将Send传递给 和 SendAsync 方法,类PingReply通过 Options 属性返回 的PingOptions实例。
有关 实例 PingOptions的初始属性值列表, PingOptions 请参阅 构造函数。
构造函数
| PingOptions() | 
		 初始化 PingOptions 类的新实例。  | 
        	
| PingOptions(Int32, Boolean) | 
		 初始化 PingOptions 类的新实例,并设置生存时间和分段值。  | 
        	
属性
| DontFragment | 
		 获取或设置一个 Boolean 值,该值控制发送到远程主机的数据的分段。  | 
        	
| Ttl | 
		 获取或设置在放弃 Ping 数据之前可以转发该数据的路由节点数。  | 
        	
方法
| Equals(Object) | 
		 确定指定对象是否等于当前对象。 (继承自 Object) | 
        	
| GetHashCode() | 
		 作为默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		 获取当前实例的 Type。 (继承自 Object) | 
        	
| MemberwiseClone() | 
		 创建当前 Object 的浅表副本。 (继承自 Object) | 
        	
| ToString() | 
		 返回表示当前对象的字符串。 (继承自 Object) |