ping Reply.options ipv4与ipv6 [英] ping reply.options ipv4 vs. ipv6

查看:123
本文介绍了ping Reply.options ipv4与ipv6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我对软件的ping解决方案的研究使我进入了msdn,并且在本文结尾处得到了解决方案.除在两台win7/ipv6-机器之间执行ping操作外,其他所有方法均正常运行:reply.Options对象为空(空)!
有人知道为什么吗?
我如何获得reply.Options?
问候
维尔纳

Hi!
My research for a ping-solution for my software lead me to msdn and i got the solution at the end of my article. All works fine except a ping between two win7/ipv6-machines: The reply.Options-object is empty(null)!
Does anybody know why?
How do i get the reply.Options?
Regards
Werner

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
 
namespace TestPing
{
  class Program
  {
    // 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;
      try
      {
        PingReply reply = pingSender.Send(args[0], timeout, buffer, options);
        Console.WriteLine("reply.Status {0} {1}", args[0], reply.Status.ToString());
        if (reply.Status == IPStatus.Success)
        {
          Console.WriteLine("Address: {0}", reply.Address.ToString());
          Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
     if (reply.Options != null) // reply.Status==Success but reply.Options is empty
                      // for a ping from ipv6-adress to ipv6-adresses
          {
            Console.WriteLine("reply.Options:");
            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);
        }
      }
      catch(Exception ex)
      {
        Console.WriteLine("Exception {0}", ex.InnerException.Message);
      }
    }
 
 
  }
}

推荐答案

感谢digimanus,但还不够:要设置ipv6选项,我不知道,如何确定,涉及哪些客户端:ipv4还是ipv6?
Thanks digimanus, but not enough: To set an option ipv6 i don''t know, how to find out, what clients are involved: ipv4 or ipv6?


这篇关于ping Reply.options ipv4与ipv6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆