How to get SSID and RSSI for Win7 using C #

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

I 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 Win7 class supported? Can anybody help?

+4
source share
2 answers

I had a similar problem when I needed to get the SSID of the currently connected Wi-Fi network, but didn’t want to create a wrapper for the API because of its complexity, so it turned out why not to 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 get the result from proc.StandardOutput.ReadToEnd (); parse what you want from the line:

 "\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" 

It's much easier to parse a string than writing a wrapper for the API. Hope this helps.

+5
source
0
source

Source: https://habr.com/ru/post/1302324/


All Articles