gpt4 book ai didi

python - 无法在Python中使用WlanGetAvailableNetworkList获取所有可用网络

转载 作者:行者123 更新时间:2023-12-01 07:41:17 25 4
gpt4 key购买 nike

我正在尝试使用WlanGetAvailableNetworkList获取所有可用网络的列表。扫描返回一个包含 NumberOfItems 的对象。当我循环基于NumberOfItems的网络数组时,它只显示第一个网络,除此之外的任何内容都会给我IndexError:无效索引。这是我的代码

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 question 相关

最佳答案

我在评论中说得太早了(所以我删除了它)。显然,win32wifi.Win32Wifi 提供了许多包装 CType 的功能,但命名空间由于诸如 from win32wifi.Win32NativeWifiApi import * 之类的语句而受到污染。无论如何,这是一个例子。

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)))
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} {: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)

输出:

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q056703966]> "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]
State: [wlan_interface_state_connected]

Networks: 4

0
SSID: [D****l Software]
Profile: [D****l Software]
Connectable: True
Signal quality: 91
Flags: 3
Security: True
Auth: DOT11_AUTH_ALGO_RSNA_PSK

1
SSID: []
Profile: []
Connectable: True
Signal quality: 85
Flags: 0
Security: True
Auth: DOT11_AUTH_ALGO_RSNA_PSK

2
SSID: [sec]
Profile: []
Connectable: True
Signal quality: 33
Flags: 0
Security: True
Auth: DOT11_AUTH_ALGO_RSNA_PSK

3
SSID: [D****l Software]
Profile: []
Connectable: True
Signal quality: 91
Flags: 0
Security: True
Auth: DOT11_AUTH_ALGO_RSNA_PSK

Done.

<小时/>

更新#0

虽然与这个问题无关,但我在处理 [SO]: How to connect to WiFi network on Windows (@CristiFati's answer) 时发现(并修复了)一些 Win32WiFi 错误。可能想看一下。

关于python - 无法在Python中使用WlanGetAvailableNetworkList获取所有可用网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56703966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com