PyWiFi 文档说明

Documentation 文档

Constants 常量

Following constants are defined in pywifi.Before using the constants, please remember to import pywifi.
以下常量在pywifi中定义。在使用常数之前,请记住import pywifi.

Interface Status 接口状态

Interface.status() will return one of the status code below.
status()将返回以下状态代码之一

const.IFACE_DISCONNECTED
const.IFACE_SCANNING
const.IFACE_INACTIVE
const.IFACE_CONNECTING
const.IFACE_CONNECTED

Authentication Algorithms 认证算法
Authentication algorithm should be assined to a Profile. For normal case, almost all the APs use open algorithm.
身份验证算法应分配给配置文件。在正常情况下,几乎所有AP都使用开放算法

const.AUTH_OPEN
const.AUTH_SHARED

Key Management Type 密钥管理类型
The key management type should be assigned to a Profile.
For normal APs, if
an AP is no security setting, set the profile akm as AKM_TYPE_NONE.
an AP is in WPA mode, set the profile akm as AKM_TYUPE_WPAPSK.
an AP is in WPA2 mode, set the profile akm as AKM_TYUPE_WPA2PSK.
AKM_TYPE_WPA and AKM_TYPE_WPA2 are used by the enterprise APs.
密钥管理类型应分配给配置文件
对于正常AP,如果
AP没有安全设置,请将配置文件akm设置为AKM_TYPE_NONE
AP处于WPA模式时,将配置文件akm设置为AKM_TYUPE_WPAPSK
AP处于WPA2模式时,将配置文件akm设置为AKM_TYUPE_WPA2PSK
企业AP使用AKM_TYPE_WPA和AKM_TYPE_WPA2

const.AKM_TYPE_NONE
const.AKM_TYPE_WPA
const.AKM_TYPE_WPAPSK
const.AKM_TYPE_WPA2
const.AKM_TYPE_WPA2PSK

Cipher Types 密码类型
The cipher type should be set to the Profile if the akm is not AKM_TYPE_NONE. You can refer to the setting of the AP you want to connect to.
如果akm不是AKM_TYPE_NONE,则应将密码类型设置到Profile配置文件。您可以参考要连接到的AP的设置

const.CIPHER_TYPE_NONE
const.CIPHER_TYPE_WEP
const.CIPHER_TYPE_TKIP
const.CIPHER_TYPE_CCMP

Network Profile 网络配置
A Profile is the settings of the AP we want to connect to. The fields of an profile:
ssid - The ssid of the AP.
auth - The authentication algorithm of the AP.
akm - The key management type of the AP.
cipher - The cipher type of the AP.
key (optinoal) - The key of the AP. This should be set if the cipher is not CIPHER_TYPE_NONE.

配置文件是我们要连接到的AP的设置。配置文件的字段有:
ssid – AP的ssid
auth – AP的身份验证算法
akm – AP的密钥管理类型
cipher – AP的密码类型
key(可选)-- AP的密码(如果密码类型不是CIPHER_TYPE_NONE,则应设置此选项)

Example:

import pywifi

profile = pywifi.Profile()
profile.ssid = 'testap'
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = '12345678'

wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
profile = iface.add_network_profile(profile)
iface.connect(profile)

Interface
An Interface means the Wi-Fi interface which we use to perform Wi-Fi operations (e.g. scan, connect, disconnect, …).
接口指我们用于执行Wi-Fi操作(例如扫描、连接、断开连接等)的Wi-Fi接口

Get interface information
In general, there will be only one Wi-Fi interface in the platform. Thus, use index 0 to obtain the Wi-Fi interface.
通常,平台中只有一个无线网卡接口。因此,使用索引0可以获得Wi-Fi接口

import pywifi

wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
Interface.name()

Get the name of the Wi-Fi interface.获取wifi接口的名字

Interface.scan()
Trigger the interface to scan APs.触发接口去扫描AP信号

Interface.scan_results()
Obtain the results of the previous triggerred scan. A Profile list will be returned.
获取上一次触发扫描的结果,将返回配置列表
Note. Because the scan time for each Wi-Fi interface is variant. It is safer to call scan_results() 2 ~ 8 seconds later after calling scan().
注意:因为每个Wi-Fi接口的扫描时间是不同的。在调用scan()后2-8秒调用scan_results()会更好

Interface.add_network_profile(profile)
Add the AP profile for connecting to later.添加AP配置文件以供以后连接

Interface.remove_all_network_profiles()
Remove all the AP profiles.移除AP所有配置

Interface.network_profiles()
Obtain all the saved AP profiles by returning a Profile list.
通过返回配置文件列表获取所有已保存的AP配置文件

Interface.connect(profile)
Connect to the specified AP by the given profile.
通过给定的配置文件连接到指定的AP
Note. As current design, add_network_profile(profile) should be called before connect(profile) is called.
注意:按照当前设计,在调用connect(profile)连接方法之前,应先调用add_network_profile(profile)

Interface.disconnect()
Disconnect current AP connection 断开当前AP连接

Interface.status()
Get the status of current status.获取当前连接状态

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值