Win7网络检测 WindowsAPICodePack
原文:http://www.cnblogs.com/yincheng01/archive/2010/05/30/2213234.html
在Windows7操作系统下,支持的网络类型越来越复杂,微软提供了WindowsAPICodePack来进行简化底层开发,
我们大家来亲自实践一下关于网络状态开发,基于WindowsAPICodePack
启动VS2010
引入dll文件,添加如下代码即可
private void LoadNetworkConnections()
{
try
{
NetworkCollection networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All);
foreach (Network n in networks)
{
// 创建 tab
TabItem tabItem = new TabItem();
tabItem.Header = string.Format("Network {0} ({1})", tabControl1.Items.Count, n.Name);
tabControl1.Items.Add(tabItem); //
StackPanel stackPanel2 = new StackPanel();
stackPanel2.Orientation = Orientation.Vertical; // 列举所有信息
AddProperty("网络名称: ", n.Name, stackPanel2);
AddProperty("网络类型: ", n.Description, stackPanel2);
AddProperty("域类型: ", n.DomainType.ToString(), stackPanel2);
AddProperty("是否连接: ", n.IsConnected.ToString(), stackPanel2);
AddProperty("是否上网: ", n.IsConnectedToInternet.ToString(), stackPanel2);
AddProperty("网络 ID: ", n.NetworkId.ToString(), stackPanel2);
AddProperty("类别: ", n.Category.ToString(), stackPanel2);
AddProperty("创建时间: ", n.CreatedTime.ToString(), stackPanel2);
AddProperty("连接时间: ", n.ConnectedTime.ToString(), stackPanel2);
AddProperty("连接: ", n.Connectivity.ToString(), stackPanel2); //
StringBuilder s = new StringBuilder();
s.AppendLine("网络连接:");
NetworkConnectionCollection connections = n.Connections;
string hh = System.Environment.NewLine;
foreach (NetworkConnection nc in connections)
{
s.AppendFormat(hh + "连接 ID: {0}" + hh + "类型: {1}" + hh + "是否连接: {2}" + hh + "是否连接因特网: {3}" + hh,
nc.ConnectionId, nc.DomainType, nc.IsConnected, nc.IsConnectedToInternet);
s.AppendFormat(hh + "适配器 ID: {0}" + hh + "连接: {1}" + hh,
nc.AdapterId, nc.Connectivity);
}
s.AppendLine(); Label label = new Label();
label.Content = s.ToString(); stackPanel2.Children.Add(label);
tabItem.Content = stackPanel2;
}
}
catch (Exception ex)
{
txtReadWrite.WriteLog("检测网络异常!" + ex.GetType().FullName + ex.Message + ex.StackTrace);
(new Win_Popup("消息", "删除数据时出错!" + ex.Message, MessageBoxButton.OK)).ShowDialog();
}
} private void AddProperty(string propertyName, string propertyValue, StackPanel parent)
{
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Horizontal; Label propertyNameLabel = new Label();
propertyNameLabel.Content = propertyName;
panel.Children.Add(propertyNameLabel); Label propertyValueLabel = new Label();
propertyValueLabel.Content = propertyValue;
panel.Children.Add(propertyValueLabel); parent.Children.Add(panel);
}
窗口代码如下:
<Grid>
<TabControl Height="Auto" HorizontalAlignment="Stretch" Margin="10,10,10,10" Name="tabControl1" VerticalAlignment="Stretch" Width="Auto">
</TabControl>
</Grid>
看下效果图吧:


通过这个接口,可以获取各个网络的信息。dll下载点这。
Win7网络检测 WindowsAPICodePack的更多相关文章
- iOS开发——网络篇——NSURLSession,下载、上传代理方法,利用NSURLSession断点下载,AFN基本使用,网络检测,NSURLConnection补充
一.NSURLConnection补充 前面提到的NSURLConnection有些知识点需要补充 NSURLConnectionDataDelegate的代理方法有一下几个 - (void)conn ...
- WinForm多线程实现HTTP网络检测工具
一.背景描述与课程介绍 明人不说暗话,跟着阿笨一起玩WinForm.本次分享课程属于<C#高级编程实战技能开发宝典课程系列>中的一部分,阿笨后续会计划将实际项目中的一些比较实用的关于C#高 ...
- ios - 高效,准确的网络检测
//网络检测 // 1.创建网络监听者管理者对象 AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager share ...
- Hyper-V虚拟机win7网络红叉,无法上网解决方法
之前一直都是玩Vmware虚拟机,后来win8之后的系统有Hyper-V虚拟机就开始接触了. Windows 中内置的Hyper-V管理器可以说是给很多人带来了惊喜!至少运行的流畅程度要比Vmware ...
- 解除win7网络限速.
在电脑刚买或者系统重装了的时候,win7系统会默认限制20%的网络速度,限制了我们的上网速度,我们可以解决这个限制,让上网变得更快 下面是操作步骤 1.开始>运行 2.输入以下命令,然后确定 g ...
- iOS网络检测
使用之前请从Apple网站下载示例:点此下载 Reachability 中定义了3种网络状态: typedef enum : NSInteger { NotReachable = ,//无网络 Rea ...
- Win7网络修复,winsock/tcpip
1.win7自带网络诊断提示没有安装一个或多个协议,ip地址为169.254.x.x,dns地址为空 2.修复winsock时,提示系统找不到指定的文件. 解决办法: 1. netsh int ip ...
- Linux网络检测手段汇总
1.iftop iftop可测量通过每一个套接字连接传输的数据:它采用的工作方式有别于nload.iftop使用pcap库来捕获进出网络适配器的数据包,然后汇总数据包大小和数量,搞清楚总的带宽使用情况 ...
- (020)[虚拟系统]Win7网络连接红叉(无解决)
该虚拟机在重装主系统前是可以连接网络的,主系统重新安装以后,导入新安装的VM以后,网络图标显示红叉. 查看设备管理,显示没有安装以太网驱动. 重新安装 Vmware Tools,未果.VMware官网 ...
随机推荐
- Spring Data JPA之Hello World
Spring Data Jpa 配置 使用 Spring Data JPA 进行持久层开发需要的四个步骤: 1.配置 Spring 整合 JPA 2.在 Spring 配置文件中配置 Spring D ...
- CloudStack添加新的API注意事项
1.***Cmd上面的@APICommand里的responseObject关联对于的Response: 2.在tomcatconf/command.properties.in添加新API的权限: 3 ...
- 测试jsp
一. get.jsp <%@ page contentType="text/html;charset=UTF-8"%> <%@ page import=" ...
- js收集错误信息,错误上报
线上的代码可有有时候用户会反应不好使,一般是因为js造成的! 尤其在移动端各个手机之前的差异特别大. 下面这段代码是获取能帮助你! <script> window.onerror = fu ...
- jquery第六期:位置选择器
<html> <head> <script type="text/javascript" src="jquery-1.10.1.js&quo ...
- linux下通过yum安装svn及配置
1.环境centos6.4 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svnserve -d -r /www/sv ...
- android的原理--为什么我们不需要手动关闭程序
内容搜集自网络,有所删改 不用在意剩余内存的大小,其实很多人都是把使用其他系统的习惯带过来来了.android大多应用没有退出的设计其实是有道理的,这和系统对进程的调度机制有关系.如果你知 ...
- (DP)House Robber
题目: You are a professional robber planning to rob houses along a street. Each house has a certain am ...
- codevs 1001 舒适的路线 (并查集)
题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光. Z小镇附近共有 N(<N≤)个景点(编号为1,,,…,N),这些景点被M(<M≤)条道路连 ...
- [转]Laravel 4之数据库操作
Laravel 4之数据库操作 http://dingjiannan.com/2013/laravel-database/ 数据库配置 Laravel数据库配置在app/config/database ...