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


            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();
            }
  • 相关阅读:
    z-index
    点击按钮跳转带指定的位置
    导航-角
    弹出框
    控制叠加风格
    Python学习三
    玩转HTTP
    http-关于application/x-www-form-urlencoded等字符编码的解释说明
    Python学习二
    git merge 和 git rebase
  • 原文地址:https://www.cnblogs.com/zhouxiaoyun/p/10765230.html
Copyright © 2020-2023  润新知