简体   繁体   English

如何以编程方式从Windows 2003 Server从无线网络设备检测密码类型和加密级别

[英]How to programmatically detect Cipher type and Encryption level from a wireless network device from windows 2003 server

Now my team working in a network project using windows application c# . 现在,我的团队正在使用Windows应用程序c#在网络项目中工作。 I didn't know how to programmatically detect Cipher type and Encryption level from a wireless network device from windows 2003 server. 我不知道如何以编程方式从Windows 2003 Server无线网络设备中检测密码类型和加密级别

After searching i got WMI (Windows Management Instrumentation) for solving the problem.+ 搜索后,我得到了WMI(Windows管理规范)来解决问题。+

Please suggest example/reference for finding Cipher type and Encryption level from a wireless network device from windows 2003 server 请提出示例/参考,以从Windows 2003 Server中从无线网络设备中查找密码类型和加密级别

just found you question. 刚刚发现您的问题。 The information which you search for originate from NDIS driver. 您搜索的信息源自NDIS驱动程序。 WMI only gives you a subset of such information. WMI仅为您提供此类信息的子集。 Every NDIS driver support some standard requests which can be send with respect of DeviceIoControl function (see http://msdn.microsoft.com/en-us/library/aa363216%28v=VS.85%29.aspx ). 每个NDIS驱动程序都支持一些可以根据DeviceIoControl函数发送的标准请求(请参阅http://msdn.microsoft.com/zh-cn/library/aa363216%28v=VS.85%29.aspx )。 As an input (lpInBuffer parameter) you should give a DWORD with an OID code, a control code which identify the request, As an output you receive a structure with information filed, or in your case a DWORD (enum value). 作为输入(lpInBuffer参数),您应该给DWORD加上OID代码,识别请求的控制代码。作为输出,您收到包含已归档信息的结构,或者在您的情况下输入DWORD(枚举值)。 For example, if you asked NDIS driver for 例如,如果您要求NDIS驱动程序提供

#define OID_802_11_WEP_STATUS                   0x0D01011B

(as DWORD value of lpInBuffer parameter) it returns back also DWORD with information like (作为lpInBuffer参数的DWORD值),它也返回DWORD并包含如下信息:

// Also aliased typedef to new name
typedef enum _NDIS_802_11_WEP_STATUS
{
    Ndis802_11WEPEnabled,
    Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
    Ndis802_11WEPDisabled,
    Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
    Ndis802_11WEPKeyAbsent,
    Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
    Ndis802_11WEPNotSupported,
    Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
    Ndis802_11Encryption2Enabled,
    Ndis802_11Encryption2KeyAbsent,
    Ndis802_11Encryption3Enabled,
    Ndis802_11Encryption3KeyAbsent
} NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
  NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;

request for 要求

#define OID_802_11_AUTHENTICATION_MODE          0x0D010118

returns 退货

typedef enum _NDIS_802_11_AUTHENTICATION_MODE
{
    Ndis802_11AuthModeOpen,
    Ndis802_11AuthModeShared,
    Ndis802_11AuthModeAutoSwitch,
    Ndis802_11AuthModeWPA,
    Ndis802_11AuthModeWPAPSK,
    Ndis802_11AuthModeWPANone,
    Ndis802_11AuthModeWPA2,
    Ndis802_11AuthModeWPA2PSK,
    Ndis802_11AuthModeMax               // Not a real mode, defined as upper bound
} NDIS_802_11_AUTHENTICATION_MODE;

request for 要求

#define OID_802_11_INFRASTRUCTURE_MODE          0x0D010108

returns 退货

typedef enum _NDIS_802_11_NETWORK_INFRASTRUCTURE
{
    Ndis802_11IBSS,
    Ndis802_11Infrastructure,
    Ndis802_11AutoUnknown,
    Ndis802_11InfrastructureMax         // Not a real value, defined as upper bound
} NDIS_802_11_NETWORK_INFRASTRUCTURE;

and so on. 等等。 You can find all different constants which you needs in ntddndis.h after installing of Windows DDK. 安装Windows DDK之后,您可以在ntddndis.h找到所需的所有不同常量。

To open a device handle you should use CreateFile function. 要打开设备句柄,应使用CreateFile函数。 Instead of file name you should give a string with the prefix "\\\\.\\" and adapter name (adapter guids). 而不是文件名,您应该给字符串加上前缀"\\\\.\\"和适配器名称(适配器向导)。 Adapter names you can enumerate with different way. 您可以使用不同的方式枚举适配器名称。 One of the easiest is the subkey names of the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Adapters . 最简单的一种是注册表项HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Adapters的子项名称。

All what I explained above work exactly like http://msdn.microsoft.com/en-us/library/aa964902%28v=VS.85%29.aspx or other examples of usage DeviceIoControl . 我上面解释的所有内容都与http://msdn.microsoft.com/zh-cn/library/aa964902%28v=VS.85%29.aspx或使用DeviceIoControl其他示例完全一样。 The full list of IoControl requests which must support some device class is described in DDK. DDK中描述了必须支持某些设备类的IoControl请求的完整列表。 I repeat one more time, that for usage of that one need only use DeviceIoControl and not write a device driver. 我再重复一遍,那一次只需要使用DeviceIoControl而不编写设备驱动程序即可。

More as 10 years ago I play a little with such requests which I described here. 大约十年前,我在这里描述了一些这样的要求。 I tested my old program works without any problems now. 我测试了我的旧程序现在可以正常工作了。 One need only use OIDs which you need and not much more. 一个只需要使用您需要的OID,而无需更多。

UPDATED: I found a good link http://pages.infinit.net/codeguru/WiFiArticle.htm which explains in other words the same what I just written. 更新:我找到了一个很好的链接http://pages.infinit.net/codeguru/WiFiArticle.htm ,换句话说,我的书面解释也是如此。 It seems to me that one use here wrong parameters in CreateFile . 在我看来,这里在CreateFile使用了错误的参数。 One have to use FILE_SHARE_READ | FILE_SHARE_WRITE 一个必须使用FILE_SHARE_READ | FILE_SHARE_WRITE FILE_SHARE_READ | FILE_SHARE_WRITE to makes all working. FILE_SHARE_READ | FILE_SHARE_WRITE使所有工作正常。 Example http://code.google.com/p/haggle/source/browse/winmobile/Haggle/WindowsWiFiUtils.cpp (see bool WindowsWiFiUtils:init() , bool WindowsWiFiUtils::setEncryptionMode(unsigned long adapterIndex, const unsigned int mode) etc) looks like much better and contain a lot of methods which can be also interesting for you. 示例http://code.google.com/p/haggle/source/browse/winmobile/Haggle/WindowsWiFiUtils.cpp (请参见bool WindowsWiFiUtils:init()bool WindowsWiFiUtils::setEncryptionMode(unsigned long adapterIndex, const unsigned int mode)等)看起来要好得多,并包含很多对您也很有趣的方法。 It is a C++ example, but it's very easy to rewrite this in C#. 这是一个C ++示例,但是用C#重写它很容易。

UPDATED 2: One more way is usage of "Native Wifi API" http://msdn.microsoft.com/en-us/library/ms706556%28VS.85%29.aspx like WlanQueryInterface (for example with wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs) or WZCQueryInterface, but it seems not supported on Windows Server 2003, what you need. 更新2:另一种方法是使用“本地Wifi API” http://msdn.microsoft.com/en-us/library/ms706556%28VS.85%29.aspx,例如WlanQueryInterface(例如,使用wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs)或WZCQueryInterface,但是您所需的Windows Server 2003似乎不支持它。 Generally "Native Wifi API" is probably more reliable way to give maximum information (or modify it), but WMI can be also a good pragmatical alternative. 通常,“本机Wifi API”可能是提供最大信息(或对其进行修改)的更可靠方法,但是WMI也是一种实用的替代方法。

As far as WMI is concerned you are fairly limited in the wireless connection information you can retrieve. 就WMI而言,您可以检索的无线连接信息非常有限。

Running a WMI query for "Select * from MSNdis_80211_WEPStatus where active=true" should give you a numerical result where: 运行WMI查询"Select * from MSNdis_80211_WEPStatus where active=true"将为您提供一个数值结果,其中:

0=WEP is in use
2=Connection is unsecured
4=WPA-PSK is in use
6=WPA is in use
7=Disconnected

To run this query from powershell you can simply do: 要从powershell运行此查询,您只需执行以下操作:

PS C:\\WINDOWS> gwmi -query "Select * from MSNdis_80211_WEPStatus where active=true" -namespace root\\wmi PS C:\\ WINDOWS> gwmi -query "Select * from MSNdis_80211_WEPStatus where active=true" -namespace root\\wmi

From C# the following should work: 在C#中,以下方法应该起作用:

using System;
using System.Management;
class Query_SelectQuery
{
    public static int Main(string[] args) 
    {
        SelectQuery selectQuery = new 
            SelectQuery("Select * from MSNdis_80211_WEPStatus where active=true");
        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher("root\wmi", selectQuery);

        foreach (ManagementObject resultVal in searcher.Get()) 
        {
            Console.WriteLine(resultVal.ToString());
        }

        Console.ReadLine();
        return 0;
    }
}

If you have multiple active wireless connections it gets more difficult because you have to get the SSID values by querying the Ndis80211Ssid property in the MSNdis_80211_ServiceSetIdentifier class. 如果您有多个活动的无线连接,则将变得更加困难,因为必须通过查询MSNdis_80211_ServiceSetIdentifier类中的Ndis80211Ssid属性来获取SSID值。

If you were on Windows {Vista, 7, Server 2008} you could run netsh wlan export from a command shell and get it to output a nice .xml file with your network settings (not including the wireless key) but I don't think there's any way to get this to work on Windows XP, Server 2003 or other unlisted operating systems. 如果您使用的是Windows {Vista,7,Server 2008},则可以从命令外壳运行netsh wlan export ,并使其通过网络设置(不包括无线密钥)输出一个不错的.xml文件,但是我不认为有任何方法可以使它在Windows XP,Server 2003或其他未列出的操作系统上运行。

Another option if you need more detailed configuration information specifically under Windows 2003 Server is to access the group policy settings as detailed in this article: http://technet.microsoft.com/en-us/library/bb878079.aspx 如果您需要更详细的配置信息(特别是在Windows 2003 Server下),则另一个选择是访问本文中详细介绍的组策略设置: http : //technet.microsoft.com/zh-cn/library/bb878079.aspx

I don't have a Windows Server 2003 machine handy to test with but you should be able to access these Group Policy Objects and settings through WMI under the root\\RSoP namespace 我没有方便进行测试的Windows Server 2003计算机,但是您应该能够通过root \\ RSoP命名空间下的WMI访问这些组策略对象和设置。

Running wbemtest from console or using the Microsoft WMI Code Creator tool will let you look around the available WMI objects and classes to figure out exactly where those Group Policy Objects are lying. 从控制台运行wbemtest或使用Microsoft WMI Code Creator工具将使您查看可用的WMI对象和类,以准确找出那些组策略对象的位置。

Querying for Group Policy WMI Objects looks kinda painful though :( 虽然查询组策略WMI对象看起来有些痛苦:(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅从域中检测Windows 2003计算机 - how to detect only windows 2003 computers from domain 从Windows Server 2008访问Windows Server 2003共享文件夹 - Access windows server 2003 share folder from windows server 2008 如何将Windows 2003 Server的时区配置从GMT更改为UTC - how to change the time zone configuration of my windows 2003 server from GMT to UTC 如何检测连接到无线网络的所有设备? - How do you detect all devices attached to your wireless network? 在Windows 7中以编程方式从系统任务栏(通知区域)中删除wifi(无线网络连接)图标 - Programatically remove wifi (Wireless Network Connection) icon from system tray (notification area) in Windows 7 通过Windows Mobile 6设备通过TCP / IP无线连接通过FTP传输图像 - FTP an image over a TCP/IP wireless connection from a Windows Mobile 6 device Windows Phone 7中的密码加密/解密 - Cipher encryption/decryption in windows phone 7 如何在Windows Server 2003中以编程方式将IP地址添加到阻止列表中? - How do I programmatically add an IP address to the blocked list in Windows Server 2003? 如何在Windows Mobile设备上设置网络连接以使用AES加密方法? - How can I set a network connection to use the AES encryption method on a Windows Mobile device? 如何使用C#在Windows中检测网络位置类型? - How to detect Network Location Type in Windows using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM