如何使用C#获取Win7的SSID和RSSI
作者:互联网
我是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?有人可以帮忙吗?
解决方法:
我有一个类似的问题,我需要获得当前连接的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.ReadToEnd()中检索输出;
从字符串中解析出你想要的东西:
"\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的包装容易得多
希望这可以帮助
标签:c,wifi,windows-7,rssi,ssid 来源: https://codeday.me/bug/20190621/1259039.html