Windows8 检测网络
来源:互联网 发布:在数据库中概念模型是 编辑:程序博客网 时间:2024/05/17 03:52
在Windows8 上检测网络很简单用到
NetworkInformation这个类
可以看到这个类里面有以下几个方法和事件
public static event NetworkStatusChangedEventHandler NetworkStatusChanged;//网络连接改变的事件public static IReadOnlyList<ConnectionProfile> GetConnectionProfiles();public static IReadOnlyList<HostName> GetHostNames();//获取HostGetInternetConnectionProfile()//详细网络配置GetConnectionProfiles()//网络概要信息
var icp = NetworkInformation.GetInternetConnectionProfile(); if (icp != null && icp.NetworkAdapter != null) { var hostname = NetworkInformation.GetHostNames().SingleOrDefault( hn => hn.IPInformation != null && hn.IPInformation.NetworkAdapter.NetworkAdapterId == icp.NetworkAdapter.NetworkAdapterId); System.Diagnostics.Debug.WriteLine("可用网络IP:" + hostname.DisplayName); System.Diagnostics.Debug.WriteLine("网络状态:" + icp.GetNetworkConnectivityLevel()); }
使用
NetworkInformation.GetInternetConnectionProfile();获取网络配置后可以得到 NetworkAdapter 网络设备
GetNetworkConnectivityLevel()得到当前网络的状态 他是一个枚举类型具体如下
// Summary: // No connectivity. 没有访问 None = 0, // // Summary: // Local network access only. 本地网络访问 LocalAccess = 1, // // Summary: // Limited internet access. This value indicates captive portal connectivity, // where local access to a web portal is provided, but access to the Internet // requires that specific credentials are provided via the portal. This level // of connectivity is generally encountered when using connections hosted in // public locations (e.g. coffee shops and book stores). // 有限的访问 ConstrainedInternetAccess = 2, // // Summary: // Local and Internet access. internet访问 InternetAccess = 3,
可以用NetworkInformation里面的 NetworkStatusChanged 监听网络改变然后在做相应的处理
- Windows8 检测网络
- windows8.1网络受限
- 网络检测
- 检测网络
- 网络检测
- 检测网络
- 网络检测
- 检测网络
- 网络检测
- Windows8核心态网络过滤研究
- windows8开发-判断网络链接状况
- windows8/winphone开发-判断网络链接状况
- Windows8共享网络让手机上网
- windows8.1/10 添加网络打印机的方法
- 检测网络是否有网络
- XP实用技巧:检测网络
- 常用网络检测命令
- 网络状态检测
- c语言 自动类型转换
- 用户并不做最佳选择:网页版块的用户体验设计
- android:音频播放
- socket阻塞详解
- buffer和cache定义
- Windows8 检测网络
- RSA公钥加密
- iOS6 Grouped类型UITableView背景色设置问题
- C++著名程序库的比较和学习经验(STL.Boost.GUI.XML.网络等等)
- JAX-WS开发Webservice(中文示例)
- swprintf/wsprintf
- xcode找不到头文件
- android:ProgressDialog实现
- 自动编译、安装iOS安装包ipa