首页 > 代码库 > C# 检查网络通畅

C# 检查网络通畅

public static bool PingServer(string ipOrHostName)
         {
             try
             {
                 Ping ping = new Ping();

                 PingOptions pingOptions = new PingOptions();

                 pingOptions.DontFragment = true;

                 string datahttp://www.mamicode.com/= "";

                 byte[] buffer = Encoding.UTF8.GetBytes(data);

                 int timeout = 120;

                 PingReply reply = ping.Send(ipOrHostName, timeout, buffer, pingOptions);

                 string result = reply.Status.ToString();

                 if (result == "Success")
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception)
             {
                 return false;
             }
         }

C# 检查网络通畅