码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET Core使用Ping判断网络是否接通

时间:2019-04-27 00:46:02      阅读:460      评论:0      收藏:0      [点我收藏+]

标签:Nging   grep   ping   end   coding   判断   sci   net   host   

        static void Main(string[] args)
        {
            // 主机地址
            string targetHost = "bing.com";
            string data = "Hello world";

            Ping pingSender = new Ping();
            PingOptions options = new PingOptions
            {
                DontFragment = true
            };

            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 1024;

            Console.WriteLine($"Pinging {targetHost}");
            //PingReply reply = pingSender.Send(targetHost, timeout, buffer, options);

            PingReply reply = pingSender.Send(targetHost, timeout);

            if (reply.Status == IPStatus.Success)
            {
                Console.WriteLine($"Address: {reply.Address}");
                Console.WriteLine($"RoundTrip time: {reply.RoundtripTime}");
                Console.WriteLine($"Time to live: {reply.Options.Ttl}");
                Console.WriteLine($"Don‘t fragment: {reply.Options.DontFragment}");
                Console.WriteLine($"Buffer size: {reply.Buffer.Length}");
            }
            else
            {
                Console.WriteLine(reply.Status);
            }

            Console.ReadLine();
        }

 

ASP.NET Core使用Ping判断网络是否接通

标签:Nging   grep   ping   end   coding   判断   sci   net   host   

原文地址:https://www.cnblogs.com/zhouxiaoyun/p/10765230.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!