如何使用C#获取Win7的SSID和RSSI [英] How to get SSID and RSSI for Win7 using C#

查看:339
本文介绍了如何使用C#获取Win7的SSID和RSSI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Win7和WMI非常陌生.请告诉我从WiFi看到主动访问点的位置,以及如何获取每个访问点的ssid/rssi.

I am very new to Win7 and WMI. Please advice me where to see for active access point from WiFi and how to get ssid/rssi for each access point.

我用过

ManagementClass mc = new ManagementClass("root\\WMI", "MSNdis_80211_ServiceSetIdentifier", null);          
ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(@"root\wmi","SELECT * FROM MSNdis_80211_BSSIList");

但是我得到0个结果.此类支持Win7吗?有人可以帮忙吗?

but I got 0 results. Is this class support Win7? Anybody can help?

推荐答案

我遇到了类似的问题,我需要获取当前连接的Wifi网络的SSID,但是由于其复杂性,我不希望为API创建包装器,因此想通了为什么不使用netsh

I had a similar problem where I needed to get the SSID of the currently connected Wifi network but didnt feel like creating a wrapper for the API due to its complexity so figured why not use netsh

        ProcessStartInfo info = new ProcessStartInfo("netsh", "wlan show interfaces");
        info.WorkingDirectory = @"%WINDIR%\system32";
        info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        info.CreateNoWindow = true;
        info.RedirectStandardOutput = true;
        info.UseShellExecute = false;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = info;
        proc.Start();

然后您可以从proc.StandardOutput.ReadToEnd();中检索输出. 从字符串中解析出您想要的内容:

then you can just retrieve the output from proc.StandardOutput.ReadToEnd(); parse out what you want from the string:

"\r\n There is 1 interface on the system: \r\n\r\n
Name                   : Wireless Network Connection\r\n
Description            : Atheros AR9285 Wireless Network Adapter\r\n
GUID                   : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\r\n
Physical address       : xx:xx:xx:xx:xx:xx\r\n
State                  : connected\r\n
SSID                   : Dynex2\r\n
BSSID                  : xx:xx:xx:xx:xx:xx\r\n
Network type           : Infrastructure\r\n
Radio type             : 802.11g\r\n
Authentication         : WPA2-Personal\r\n
Cipher                 : CCMP\r\n
Connection mode        : Auto Connect\r\n
Channel                : 1\r\n
Receive rate (Mbps)    : 54\r\n
Transmit rate (Mbps)   : 54\r\n
Signal                 : 100% \r\n
Profile                : Dynex2 \r\n\r\n
Hosted network status  : Not available\r\n\r\n"

解析字符串比为API编写包装器容易得多 希望这会有所帮助

Much easier to parse a string than to write a wrapper for the API Hope this helps

这篇关于如何使用C#获取Win7的SSID和RSSI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆