当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 关于网络连接状态的编程

ASP.NET
调用另外一个同名的重载函数漏掉括号出现的严重问题
DataGrid模板列应用:在DataGrid中用CheckBox控制TextBox的Enabled属性
使用存储过程的一个小例子
.net中xmlhttp下载文件的方法参考
简单的c#文本文件读写
我的C#学习过程 第一天 安装
在数据库中开始一个事务。
用ASP.NETt实现简单的文字水印
C/S系统中三层结构(Com/Com+)的测试成功实现
VB 二进制块读写类模块应用实例,包括一个文件拷贝和一个文件二进制比较的例子。
扫雷程序“布雷”代码(vb)
关于网络连接状态的编程
c#中ref和out参数使用时需要注意的问题
use Assembly to call a method
在VBA中调用AUTOCAD打印文件
在VS.NET的
昨天折腾了一晚上,哪位高手帮我看看!急!
Net是未来的趋势吗?
如何修改自定义Webpart 的标题(downmoon)
[收藏]ASP.Net生成静态HTML页 选择自 coofucoo 的 Blog

ASP.NET 中的 关于网络连接状态的编程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 29 ::
收藏到网摘: n/a

1. 可以用WMI (Win2K & XP):(首先要在VS.NET中创建一个项目,然后在添加引用中引用一个.net的装配件:System.Management.dll,这样你的项目才能使用WMI)with Windows 2000 & XP, UNDOCUMENTED: MSNdis_MediaConnectStatus - NdisMediaConnectStatus : (0 = connected?, 1 = not connected?)with Windows XP: Win32_NetworkAdapter - NetConnectionStatus : using System.Management;static void ReportConnection2000(){ ManagementClass mc = new ManagementClass( @"root\WMI", @"MSNdis_MediaConnectStatus", null ); ManagementObjectCollection moc = mc.GetInstances(); foreach( ManagementObject mo in moc ) { string name = (string) mo["InstanceName"]; bool active = (bool) mo["Active"]; uint status = (uint) mo["NdisMediaConnectStatus"]; Console.WriteLine( " {0}\n\tActive:{1} Media Status:{2}", name, active, status ); }}static void ReportConnectionXP(){ ManagementClass mc = new ManagementClass( @"Win32_NetworkAdapter" ); ManagementObjectCollection moc = mc.GetInstances(); foreach( ManagementObject mo in moc ) { string name = (string) mo["Name"]; object val = mo["NetConnectionStatus"]; if( val != null ) Console.WriteLine( " {0}\n\tConnection Status:{1}", name, (ushort) val ); else Console.WriteLine( " {0}\n", name ); }}如果返回0则表示连接;如果返回1则表示没连接;上面得到的是本地的连接状态;==========================================================利用ping来得取: Process p = new Process(); p.StartInfo .WorkingDirectory ="c:\\"; p.StartInfo.FileName = "ping.exe"; p.StartInfo.Arguments="192.168.52.31"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.Start (); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit (); MessageBox.Show(output);//得到ping的输出值