跨平台的pywifi模块支持操作无线网卡,该模块易于使用,同时支持Windows、Linux等多个系统。pywifi模块不是Python的标准模块,需单独安装,同时该模块依赖comtypes模块,最好...
跨平台的pywifi模块支持操作无线网卡,该模块易于使用,同时支持Windows、linux等多个系统。pywifi模块不是python的标准模块,需单独安装,同时该模块依赖comtypes模块,最好同时安装comtypes模块,否则调用pywifi的函数时可能会报错。
pip install comtypes pip install pywifi
pywifi模块中的类不算太多,其中主要用到的类包括PyWiFi、Profile、Interface等,详述如下:
PyWiFi类用于操作无线设备,该类的主要函数interfaces返回可用的无线网卡集合,也即Interface对象集合。
Profile类表示无线接入点(AP),也即无线网卡搜索出的无线连接,一个Profile对象表示一个可以连接或可用的无线连接,Profile类的主要属性如下表所示:
;Interface类用于执行无线网络操作,主要包括以下函数:
最后是照着参考文献3编写的测试程序(测试前请确保已记住当前计算机连接的wifi密码)
import pywifi
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
print('interface name: ',iface.name())
print('interface status: ',iface.status())
iface.disconnect()
print('interface status: ',iface.status())
profile = pywifi.Profile()
profile.ssid = "XXXXXXX"
profiandroidle.auth = pywifi.const.AUTH_ALG_OPEN
profile.akm.append(pywifi.const.AKM_TYPE_WPA2PSK)
profile.cipher = pywifi.const.CIPHER_TYPE_CCMP
profile.key = 'XXXXXXX'
iface.remove_all_network_profiles()
tep_profile = iface.add_network_profile(profile)
iface.connect(tep_profile)
sleep(5)
print('interface status: ',iface.status())
参考文献
[1]https://github.com/awkman/pywifi
[2]https://github.com/awkman/pywifi/blob/master/DOC.md
[3]https://blog.csdn.net/Feng_liangmu/article/details/122911002
[4]https://docs.python.org/zh-cn/3/index.html
[5]https://www.likecs.com/show-655827.html
[6]https://www.likecs.com/show-655827.html
[7]https://code84.com/739564.html
到此这篇关于Python中pywifi模块的基本用法的文章就介绍到这了,更多相关Python pywifi模块内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!










