python的wpa请求包装器
wpa_supplicant的Python项目详细描述
动机
这个库提供了一个到wpa_请求d-bus的接口 接口。到目前为止,还没有一个好的接口选择 使用Python的WPAI请求器,并进一步说明现有的 d-bus库很难使用。这个图书馆把所有的 把它转换成一个基于wpa_supplicant D-Bus documentation的非常干净的api。
概述
这个库不仅仅是一个可以使用的库 在编程上,它还可以作为一个命令行工具方便地使用 wpa_恳求和行使图书馆。
下面是创建无线接口(wlan0)和 正在执行扫描。
使用库:
fromwpa_supplicant.coreimportWpaSupplicantDriverfromtwisted.internet.selectreactorimportSelectReactorimportthreadingimporttime# Start a simple Twisted SelectReactorreactor=SelectReactor()threading.Thread(target=reactor.run,kwargs={'installSignalHandlers':0}).start()time.sleep(0.1)# let reactor start# Start Driverdriver=WpaSupplicantDriver(reactor)# Connect to the supplicant, which returns the "root" D-Bus object for wpa_supplicantsupplicant=driver.connect()# Register an interface w/ the supplicant, this can raise an error if the supplicant# already knows about this interfaceinterface=supplicant.create_interface('wlan0')# Issue the scanscan_results=interface.scan(block=True)forbssinscan_results:printbss.get_ssid()
使用cli,您可以通过两个命令来执行此操作:
$ wpa create_interface wlan0 Interface(Path: /fi/w1/wpa_supplicant1/Interfaces/5, Name: wlan0, State: disconnected) OK $ wpa interface wlan0 scan BSS(Path: /fi/w1/wpa_supplicant1/Interfaces/3/BSSs/13, SSID: WINKHUB-107, BSSID: B4:79:A7:17:38:B5, Signal: -75dBm), BSS(Path: /fi/w1/wpa_supplicant1/Interfaces/3/BSSs/20, SSID: Stage, BSSID: 04:18:D6:67:2A:9C, Signal: -67dBm), BSS(Path: /fi/w1/wpa_supplicant1/Interfaces/3/BSSs/22, SSID: DAP-GUEST, BSSID: 00:07:7D:34:DB:BD, Signal: -73dBm), BSS(Path: /fi/w1/wpa_supplicant1/Interfaces/3/BSSs/24, SSID: HaberHive, BSSID: E0:1C:41:B5:6F:D5, Signal: -71dBm), BSS(Path: /fi/w1/wpa_supplicant1/Interfaces/3/BSSs/25, SSID: CMLS Guest WiFi, BSSID: 02:18:4A:91:E9:50, Signal: -79dBm), BSS(Path: /fi/w1/wpa_supplicant1/Interfaces/3/BSSs/26, SSID: Shout Public, BSSID: 0A:18:D6:67:27:9E, Signal: -77dBm), BSS(Path: /fi/w1/wpa_supplicant1/Interfaces/3/BSSs/29, SSID: ThinkTank, BSSID: 00:12:5F:03:AD:B4, Signal: -79dBm)] OK
安装
$ pip install wpa_supplicant
功能覆盖图
通常,向库中添加命令或方法非常简单 但是根据我的经验,由于d-bus的有限性,它是更好的 在库中具有映射到 D-BUS接口,即使实现起来也很千篇一律。
以下是当前的功能覆盖范围:
Object | Method | Supported |
---|---|---|
root | CreateInterface | Yes |
RemoveInterface | Yes | |
GetInterface | Yes | |
Get (properties) | Yes | |
Set (properties) | Yes | |
Register (signal) | Yes | |
Interface | Scan | Yes |
Disconnect | Yes | |
AddNetwork | Yes | |
RemoveNetwork | Yes | |
RemoveAllNetworks | Yes | |
SelectNetwork | Yes | |
Reassociate | * | |
Reattach | * | |
AddBlob | * | |
RemoveBlob | * | |
GetBlob | * | |
AutoScan | * | |
TDLSDiscover | * | |
TDLSSetup | * | |
TDLSStatus | * | |
TDLSTeardown | * | |
EAPLogoff | * | |
EAPLogon | * | |
NetworkReply | * | |
SetPKCS11EngineAndModulePath | * | |
SignalPoll | * | |
FlushBSS | * | |
SubscribeProbReq | * | |
UnsubscribeProbReq | * | |
Get (properties) | Yes | |
Set (properties) | Yes | |
Register (signal) | Yes | |
Interface.WPS | Start | * |
Get (properties) | * | |
Set (properties) | * | |
Register (signal) | * | |
Interface.P2PDevice | Find | * |
StopFind | * | |
Listen | * | |
ExtendedListen | * | |
PresenceRequest | * | |
ProvisionDiscoveryRequest | * | |
Connect | * | |
GroupAdd | * | |
Invite | * | |
Disconnect | * | |
RejectPeer | * | |
Flush | * | |
AddService | * | |
DeleteService | * | |
FlushService | * | |
ServiceDiscoveryRequest | * | |
ServiceDiscoveryResponse | * | |
ServiceDiscoveryCancelRequest | * | |
ServiceUpdate | * | |
Register (signal) | * | |
BSS | Get (properties) | Yes |
Set (properties) | Yes | |
Register (signal) | Yes | |
Network | Get (properties) | Yes |
Set (properties) | Yes | |
Register (signal) | Yes | |
Peer | Get (properties) | * |
Set (properties) | * | |
Register (signal) | * | |
Group | Get (properties) | * |
Set (properties) | * | |
Register (signal) | * | |
PersistentGroup | Get (properties) | * |
Set (properties) | * | |
Register (signal) | * |
许可证
这个软件是开源的。版权所有(C),Digi International Inc., 2015年。
此源代码表单受mozilla public条款的约束 执照,2.0版。如果MPL的一个副本没有与此一起分发 文件,您可以在http://mozilla.org/MPL/2.0/获得一个。
Digi、Digi International、Digi徽标、Digi网站和Digi 设备云是Digi的商标或注册商标 国际公司在美国和世界其他国家。 所有其他商标均为其各自所有者的财产。
软件和相关技术信息按“原样”提供 无任何明示或暗示的保证,包括但不包括 仅限于适销性的保证,适合特定的 目的和非侵权。在任何情况下,迪吉或其子公司 对任何索赔、损害或其他责任负责,无论是 合同诉讼、侵权诉讼或其他诉讼,由 与本软件和技术信息的连接,包括 所有源代码和目标代码,无论如何使用。你同意 不禁止您接收本软件和技术 美国和其他适用国家出口信息 控制法律法规,并遵守所有 适用的美国和其他国家出口法律法规 关于软件和技术的使用、出口或再出口 信息。