如何使用 python 查找并连接所有可用的 wifi 信号?

How to find all and connect all available wifi signals using python?

我正在 raspberry pi 寻找并连接所有可用的 wifi 连接。如何使用 python 查找并列出所有可用的 WIFI 网络。我们可以使用 python 套接字打印所有可用的 wifi 连接吗?如果套接字不能完成这项工作,那么我们可以使用哪个库来完成这项工作?

我认为 python 中最好的 wifi 操作模块之一是 wifi 包。

pip install wifi

简单的用例是; (将 "wlan0" 替换为您的无线设备 ID)

from wifi import Cell, Scheme
list(Cell.all('wlan0'))

这将 return 一个 Cell 对象列表。每个对象将具有以下属性:

  • ssid
  • 信号
  • 质量
  • 频率
  • 比特率
  • 加密
  • 频道
  • 地址
  • 模式

对于加密为True的单元格,还会有以下属性:

  • encryption_type

连接到 AP;

cell = list(Cell.all('wlan0'))[0]
scheme = Scheme.for_cell('wlan0', 'home', cell, passkey)
scheme.save()
scheme.activate()

scheme = Scheme.find('wlan0', 'home')
scheme.activate()

有关更多信息,请转到 https://wifi.readthedocs.io/en/latest/