码迷,mamicode.com
首页 > Windows程序 > 详细

C# 检查网络通畅

时间:2016-08-29 19:08:17      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

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

                 PingOptions pingOptions = new PingOptions();

                 pingOptions.DontFragment = true;

                 string data = "";

                 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# 检查网络通畅

标签:

原文地址:http://www.cnblogs.com/zhaoCat/p/5818999.html

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