- public class Net
- {[DllImport("wininet")]
- private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
- ///
- /// 检测本机是否联网
- ///
- ///
- public static bool IsConnectedInternet()
- {
- int i = 0;
- if (InternetGetConnectedState(out i, 0))
- {
- // 已联网
- return true;
- }
- else
- {
- // 未联网
- return false;
- }
- }
- }
- C# 检测本机是否联网
来源: http://www.bubuko.com/infodetail-2646355.html