Pywifi的使用

Pywifi在今日头条上看到有人在使用,也尝试的学着如果去运用,根据官网的链接尝试的编码是可以运行的,如果你想要更加完善,则看你的应用领域在哪

参考官网API 文档链接 (https://pypi.org/project/pywifi/)。参考github的链接(https://github.com/awkman/pywifi/blob/master/DOC.md

import pywifi

from pywifi import const

profile = pywifi.Profile()

profile.ssid ='名称' #wifi名称

profile.auth = const.AUTH_ALG_OPEN#验证方式

profile.akm.append(const.AKM_TYPE_WPA2PSK)#加密方式

profile.cipher = const.CIPHER_TYPE_CCMP#加密类型

profile.key ='密码' #你要连接的wifi密码

wifi = pywifi.PyWiFi()

iface = wifi.interfaces()[0]

temp = iface.add_network_profile(profile)

iface.connect(temp)

在这里需要注意的是,需要导入 const的类,否则无法识别,这是和官网上有点不一样的,接口的状态描述你可以细究github中描述的手册,interface.status()返回的状态信息为0~4,分别对应const.IFACE_DISCONNECTED的各个链接。运行过程中还有一个坑,运行pywifi需要下载comtypes 的库。以下是未下载时的报错信息

在这里插入图片描述

在参考github文中的interface.status() 则对应上文中iface.status(),以上便是pywifi库的使用

发布了18 篇原创文章 · 获赞 0 · 访问量 279

猜你喜欢

转载自blog.csdn.net/weixin_41597669/article/details/104263495