在Python中使用WlanScan强制进行wifi扫描 [英] Force wifi scan using WlanScan in Python

查看:413
本文介绍了在Python中使用WlanScan强制进行wifi扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从python执行 WlanScan 函数来启动无线网络扫描。我正在使用python模块 win32wifi 。它需要使用 WlanOpenHandle 和接口GUID pInterfaceGuid 获得的句柄。我不知道如何获取此GUID。任何帮助都将不胜感激。

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.

< img src = https://i.stack.imgur.com/wBjlZ.png alt =我如何获得此pInterfaceGuid>

推荐答案

我安装了 Win32WiFi 模块,并在简短检查了@Castorix提供的 URL 之后(所有必需的信息都可以在< a href = https://docs.microsoft.com/en-gb/windows/desktop/api/wlanapi rel = nofollow noreferrer> [MS.Docs]:wlanapi.h标头),以及源代码,我能够写出这个小例子。

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():
    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 {0:s} {1:d}bit on {2:s}\n".format(" ".join(item.strip() for item in sys.version.split("\n")), 64 if sys.maxsize > 0x100000000 else 32, sys.platform))
    main()
    print("\nDone.")

输出


[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)] 64bit on win32

WLAN Interfaces: 1

  0
  GUID: [{0C58E048-BC0B-4D5F-A21F-FCD4E4B31806}]
  Description: [Intel(R) Dual Band Wireless-AC 8260]

  Scan result: 0

Done.



根据[SO]:无法使用WlanGetAvailableNetworkList获取所有可用网络使用Python(@CristiFati的答案)。现在它将适用于具有多个 WLAN 适配器

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

这篇关于在Python中使用WlanScan强制进行wifi扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆