admin管理员组

文章数量:1530517

Python中Pywifi扫描不到附近wifi列表的疑问(待解决)

源代码

from tkinter import  *
from pywifi import const
import pywifi
import time

# 导入模块
# 获取第一个无线网卡
# 断开所有的Wifi连接
# 读取密码字典
# 设置睡眠时间,有响应时间让其连接成功

#测试密码
def wificonnect(str,wifiname):
    #创建无线对象
    wifi = pywifi.PyWiFi()
    #抓取第一个无线网卡
    ifaces = wifi.interfaces()[0]
    #断开所有wifi连接
    ifaces.disconnect()
    time.sleep(1)

    #判断连接状态
    if ifaces.status() == const.IFACE_DISCONNECTED:
        #创建wifi连接文件
        profile = pywifi.Profile()
        #wifi名字
        profile.ssid = wifiname
        #wifi的加密算法
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        #wifi的密码
        profile.key = str
        #网卡的开放状态
        profile.auth = const.AUTH_ALG_OPEN
        #删除所有的wifi连接文件
        ifaces.remove_all_network_profiles()
        #设定新的连接文件
        tep_profile = ifaces.add_network_profile(profile)
        #连接网络
        ifaces.connect(tep_profile)
        time.sleep(5)

本文标签: 疑问列表PythonPywifiwifi