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 }
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 }