I am trying to get the list of all available networks using WlanGetAvailableNetworkList
. The scan returns an object which contains NumberOfItems
. When I loop over the array of networks based NumberOfItems
it only shows me the first network and anything beyond that gives me IndexError: invalid index
.
here's my code
from win32wifi.Win32Wifi import WlanScan, WlanOpenHandle, WlanGetProfileList, WlanEnumInterfaces, WlanGetAvailableNetworkList, WlanCloseHandle, WlanConnect
handle =WlanOpenHandle()
interfaces = WlanEnumInterfaces(handle).contents
g= interfaces.InterfaceInfo[0].InterfaceGuid
WlanScan(handle, g)
networks= WlanGetAvailableNetworkList(handle, g).contents
print("Number of networks : ", networks.NumberOfItems)
for i in range(networks.NumberOfItems):
print('Network : ', networks.Network[i].dot11Ssid.SSID )
WlanCloseHandle(handle)
this questions is related to this question
I spoke too soon in my comment (so I deleted it). Apparently, win32wifi.Win32Wifi offers lots of functionalities that wrap CTypes, but the namespace is polluted because of statements like
from win32wifi.Win32NativeWifiApi import *
. Anyway, here's an example.code00.py:
Output:
Update #0
Although it's not related to this question, I found (and fixed) some Win32WiFi bugs while working on [SO]: How to connect to WiFi network using Python 3? (@CristiFati's answer). Might want to take a look.