1 ///2 /// 是否能 Ping 通指定的主机 3 /// 4 /// ip 地址或主机名或域名 5 ///true 通,false 不通 6 public bool Ping(string ip) 7 { 8 System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); 9 System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();10 options.DontFragment = true;11 string data = "Test Data!";12 byte[] buffer = Encoding.ASCII.GetBytes(data);13 int timeout = 1000; // Timeout 时间,单位:毫秒14 System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);15 if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)16 return true;17 else18 return false;19 }