1  /// <summary>
 2         /// 检测连接指定主机网络状况
 3         /// </summary>
 4         /// <param name="host">主机名:可以为IP或者一級域名</param>
 5         /// <returns>true连接正常,false无法正常连接</returns>
 6         public static bool Check(string host)
 7         {
 8             bool isOk = false;
 9             Ping ping = new Ping();
10             PingOptions options = new PingOptions();
11             options.DontFragment = true;
12             PingReply reply = null;
13             try
14             {
15                 reply = ping.Send(host);
16                 if (reply.Status == IPStatus.Success)
17                 {
18                     isOk = true;
19                 }
20                 else
21                 {
22                     isOk = false;
23                 }
24             }
25             catch(Exception exc)
26             {
27                 isOk = false;
28             }            
29             return isOk;
30         }

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2021-07-20
  • 2021-07-16
  • 2022-12-23
猜你喜欢
  • 2021-11-09
  • 2021-09-17
  • 2021-12-03
  • 2022-03-01
  • 2022-02-11
  • 2022-02-03
相关资源
相似解决方案