如何使用C#获取Win7的SSID和RSSI

发布于 2024-08-23 01:47:35 字数 373 浏览 6 评论 0原文

我对Win7和WMI很陌生。请告诉我在哪里可以看到 WiFi 的活动接入点以及如何获取每个接入点的 ssid/rssi。

我有使用:

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

但我得到了 0 个结果。这个类支持Win7吗?有人可以帮忙吗?

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.

I have use:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠意 2024-08-30 01:47:35

我遇到了类似的问题,我需要获取当前连接的 Wifi 网络的 SSID,但由于其复杂性,我不想为 API 创建包装器,所以我想为什么不使用 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 检索输出。读到结束();
从字符串中解析出您想要的内容:

"\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 编写包装器容易得多
希望这有帮助

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();

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"

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

北方的巷 2024-08-30 01:47:35

除了 WMI,您还可以使用托管 Wifi API

检查这个问题
获取我在 Windows Vista 上使用 C# .Net 连接到的无线网络的 SSID

有时我使用 delphi-prism 编写了一个示例,与 C# 非常相似。
http://theroadtodelphi.wordpress.com /2009/09/30/使用-delphi-prism检测-wifi-网络/

Instead of WMI you can use the Managed Wifi API.

Check this question
Get SSID of the wireless network I am connected to with C# .Net on Windows Vista

Some time a go i wrote an example using delphi-prism, is very similar to C#.
http://theroadtodelphi.wordpress.com/2009/09/30/detecting-wifi-networks-using-delphi-prism/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文