zoukankan      html  css  js  c++  java
  • 使用C#ping主机的方法

    在我们开发项目时经常会遇到要ping主机的问题,现在我封装了一个ping主机的方法,

    代码如下:      

            /// <summary>

            /// Ping指定的主机,看能否ping通
            /// </summary>
            /// <param name="Address">(主机地址)</param>
            /// <param name="TimeOut">(超时时间,默认:1s)</param>
            /// <returns>True if a response is received, false otherwise</returns>
            public static bool PingHost(string Address, int TimeOut = 1000)
            {
                using (System.Net.NetworkInformation.Ping PingSender = new System.Net.NetworkInformation.Ping())
                {
                    PingOptions Options = new PingOptions();
                    Options.DontFragment = true;
                    string Data = "test";
                    byte[] DataBuffer = Encoding.ASCII.GetBytes(Data);
                    PingReply Reply = PingSender.Send(Address, TimeOut, DataBuffer, Options);
                    if (Reply.Status == IPStatus.Success)
                        return true;
                    return false;
                }
            }
  • 相关阅读:
    Handsontable添加超链接
    Handsontable 筛选事件
    handsontable自定义渲染
    M1 Mac安装 Homebrew
    Pypi官网怎么找历史依赖包
    在 CentOS7 中我们在安装 MySQL
    Ansible使用yum安装
    Ansible集群自动化运维操作
    java对list中map集合中某个字段排序
    使用hive的orcfiledump命令查看orc文件
  • 原文地址:https://www.cnblogs.com/kevinGao/p/2336477.html
Copyright © 2011-2022 走看看