I want to get a list of the wifi networks around the system in rust on Windows.
I can successfully retrieve the Wifi adapter and scan networks.
However when I want to enumerate the available Wifi networks using WlanGetNetworkBssList
or WlanGetAvailableNetworkList
it reports it has found ~around 10 networks~ everytime but the actual list i get is only 1 item long. Here is my code:
pub unsafe fn get_networks_no_error_handling() {
let mut client_handle: *mut _ = null_mut();
let mut version: u32 = 0;
const MAX_CLIENT_VERSION: u32 = 2;
WlanOpenHandle(MAX_CLIENT_VERSION, null_mut(), &mut version, &mut client_handle);
let mut iface_list: *mut WLAN_INTERFACE_INFO_LIST = null_mut();
WlanEnumInterfaces(client_handle, null_mut(), &mut iface_list);
let iface_list = &*iface_list;
let iface_info: WLAN_INTERFACE_INFO = iface_list.InterfaceInfo[0];
WlanScan(client_handle, &iface_info.InterfaceGuid, null(), null_mut(), null_mut());
let mut bss_list: *mut WLAN_BSS_LIST = null_mut();
WlanGetNetworkBssList(client_handle, &iface_info.InterfaceGuid, null(), 0, 0, null(), &mut bss_list);
let bss_list = unsafe { &*bss_list };
if bss_list.dwNumberOfItems != 0 {
for i in 0..(bss_list.dwNumberOfItems-1) {
let bss = &bss_list.wlanBssEntries[i as usize];
println!(
"SSID: {:?}, Signal Quality: {}",
String::from_utf8_lossy(&bss.dot11Ssid.ucSSID[0..bss.dot11Ssid.uSSIDLength as usize]),
bss.lRssi
);
}
}
WlanCloseHandle(client_handle, null_mut());
}
As I mentioned I tried using WlanGetAvailableNetworkList
and WlanGetNetworkBssList
with no success.
EDIT: I removed the error handling to make it more readable as it does not affect the output of the code.
Barnabás is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1