How to get all available networks using WlanGetAvailableNetworkList in Python

Development | Programming languages
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 )
No attachments
#!/usr/bin/env python3
import sys
from win32wifi import Win32Wifi as ww

def main():
    interfaces = ww.getWirelessInterfaces()
    print("WLAN Interfaces: {:d}".format(len(interfaces)))
    for idx0, interface in enumerate(interfaces):
        print("\n  {:d}\n  GUID: [{:s}]\n  Description:  [{:s}]\n  State: [{:s}]".format(idx0, interface.guid_string, interface.description, interface.state_string))
        networks = ww.getWirelessAvailableNetworkList(interface)
        print("\n  Networks: {:d}".format(len(networks)))
        for idx1, network in enumerate(networks):
            print("\n    {:d}\n    SSID: [{:s}]\n    Profile: [{:}]\n    Connectable: {:}\n    Signal quality: {:d}\n    Flags: {:d}\n    Security: {:}\n    Auth: {:}".format(
                idx1, network.ssid.decode(), network.profile_name, network.connectable, network.signal_quality, network.flags, network.security_enabled, network.auth))

if __name__ == "__main__":
    print("Python {:s} on {:s}\n".format(sys.version, sys.platform))

on June 22nd, 2019 (5:03 pm)
All coments
This job has not been commented yet.
You must sign in to comment!! LOGIN
We use cookies to give you the best possible experience on our site. By continuing to use the site you agree to our use of cookies. Find out more Accept