Reputation: 201
I have the following code and try to find the MAC address of the AP. The code runs, but it does not return anything. What am I doing wrong?
using System;
using System.Management;
public class wifiTest
{
public static int Main(string[] args)
{
String query = "SELECT * FROM MSNDis_80211_BSSIList";
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root/WMI", query);
ManagementObjectCollection moc = searcher.Get();
ManagementObjectCollection.ManagementObjectEnumerator moe = moc.GetEnumerator();
moe.MoveNext();
ManagementBaseObject[] objarr = (ManagementBaseObject[])moe.Current.Properties["Ndis80211BSSIList"].Value;
foreach (ManagementBaseObject obj in objarr)
{
uint u_rssi = (uint)obj["Ndis80211Rssi"];
int rssi = (int)u_rssi;
int macAd = (int)obj["Ndis80211MacAddress"];
Console.WriteLine("RSSI=" + rssi);
Console.WriteLine("Mac=" + macAd);
}
return 0;
}
}
Upvotes: 1
Views: 1394
Reputation: 136431
The MSNDis_80211_BSSIList
retrieve data only if the driver of your wifi adapter implements a WMI provider for such class. for an alternative consider use the Native Wifi API
if you are using C# check this project Managed Wifi API
.
Upvotes: 2
Reputation: 38152
When dealing with WMI in managed code, I strongly suggest you use the Management Strongly Typed Class Generator, instead of dealing with ManagementObjectSearcher
objects and the likes directly.
The Management Strongly Typed Class Generator tool enables you to quickly generate an early-bound managed class for a specified Windows Management Instrumentation (WMI) class. The generated class simplifies the code you must write to access an instance of the WMI class.
This tool is automatically installed with Visual Studio and with the Windows SDK.
In addition, you'd might want to get familiar with wbemtest, which is a simple tool with which you can check your queries.
Upvotes: 0