Util.cs 937 Bytes
using HHECS.Bll;
using HHECS.Model.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HHECS
{
    public  class Util
    {
        public static bool PingTest(String IP)
        {
            bool returnValue = false;
            try
            {
                System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();

                System.Net.NetworkInformation.PingReply pingStatus = ping.Send(System.Net.IPAddress.Parse(IP), 20);

                if (pingStatus.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"PING[{IP}]的时候,发生错误:{ex.Message}", LogLevel.Exception);
            }
            return returnValue;
        }
    }
}