I want to know how to execute the WlanScan
function from python to initiate a wireless network scan. I am using python module win32wifi. It requires a handle obtained using WlanOpenHandle
and an interface GUID pInterfaceGuid
. I have no idea how to get this GUID. any help would be appreciated.
Asked
Active
Viewed 901 times
2

HaMAD
- 787
- 2
- 6
- 11
-
Could you post your code? – CristiFati Jun 21 '19 at 10:51
2 Answers
2
You get the Guid with WlanEnumInterfaces which returns WLAN_INTERFACE_INFO_LIST structure with WLAN_INTERFACE_INFO structure and InterfaceGuid member

Castorix
- 1,465
- 1
- 9
- 11
-
I have read this documentation. How do I access the InterfaceGuid member ? – HaMAD Jun 21 '19 at 10:42
-
You can find Python samples on Google with those keywords. For example :[Wifi python](https://fraoustin.fr/old/python_wifi.html) – Castorix Jun 21 '19 at 11:15
2
I installed the Win32WiFi module and after a brief check of URLs provided by @Castorix (all required info can be found at [MS.Docs]: wlanapi.h header), and the source code, I was able to write this small example.
code00.py:
#!/usr/bin/env python3
import sys
from win32wifi import Win32Wifi as ww
def main(*argv):
interfaces = ww.getWirelessInterfaces()
print("WLAN Interfaces: {:d}".format(len(interfaces)))
handle = ww.WlanOpenHandle()
for idx , interface in enumerate(interfaces):
print("\n {:d}\n GUID: [{:s}]\n Description: [{:s}]".format(idx, interface.guid_string, interface.description))
try:
scan_result = ww.WlanScan(handle, interface.guid)
except:
print(sys.exc_info())
continue
print("\n Scan result: {:d}".format(scan_result))
ww.WlanCloseHandle(handle)
if __name__ == "__main__":
print("Python {:s} {:03d}bit on {:s}\n".format(" ".join(elem.strip() for elem in sys.version.split("\n")),
64 if sys.maxsize > 0x100000000 else 32, sys.platform))
rc = main(*sys.argv[1:])
print("\nDone.")
sys.exit(rc)
Output:
[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q056701614]> "e:\Work\Dev\VEnvs\py_pc064_03.07.06_test0\Scripts\python.exe" code00.py Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] 064bit on win32 WLAN Interfaces: 1 0 GUID: [{0C58E048-BC0B-4D5F-A21F-FCD4E4B31806}] Description: [Intel(R) Dual Band Wireless-AC 8260] Scan result: 0 Done.
Update #0
Updated the code according to [SO]: Unable to get all available networks using WlanGetAvailableNetworkList in Python (@CristiFati's answer). It will now work for computers that have more than one WLAN adapter.

CristiFati
- 38,250
- 9
- 50
- 87
-
-
What do you mean? Which array can't be indexed? I am able to index it: `interfaces.InterfaceInfo[i]`. – CristiFati Jun 21 '19 at 11:43
-
I'm getting an error while using the above logic on getting list of available networks. only 0 index works others dont work even if there are more networks accoring to `NumberOfItems` – HaMAD Jun 21 '19 at 12:13
-
I'm getting an error while using the above logic on getting list of available networks. only 0 index works others dont work even if there are more networks accoring to `NumberOfItems` – HaMAD Jun 21 '19 at 12:13
-
**Those are not available networks**, but *WLAN* interfaces on your computer (typically each computer has (a physical) one). How many do you say are on yours? What's the output on your computer? – CristiFati Jun 21 '19 at 12:22
-
I understand that the code above is for interfaces and not for networks. I tried to translate the same logic to show available networks. using `WlanGetAvailableNetworkList` and iterating over the `Network` object found within it. The issue is no matter what the `NumberOfItems` is I can only print the first network and can't go beyond that. – HaMAD Jun 21 '19 at 12:28
-
You should add your code to the question. Note that what you're asking now is different than the original question. – CristiFati Jun 21 '19 at 12:31
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195345/discussion-between-hamad-and-cristifati). – HaMAD Jun 21 '19 at 12:32