using System.Net.NetworkInformation;
var address = "www.baidu.com";
Ping ping = null;
try {
ping = new Ping();
var pingReply = ping.Send(address);
if (pingReply == null) return false;
return pingReply.Status == IPStatus.Success;
} finally {
if (ping != null) {
// 2.0 下ping 的一个bug,需要显示转型后释放
IDisposable disposable = ping;
disposable.Dispose();
ping.Dispose();
}
}