//pip install pywifi import pywifi,time from pywifi import const import subprocess
def wifi_connect_status(): """ 判断本机是否有无线网卡,以及连接状态 :return: 已连接或存在无线网卡返回1,否则返回0 """ #创建一个元线对象 wifi = pywifi.PyWiFi() #取当前机器,第一个元线网卡 iface = wifi.interfaces()[0] #有可能有多个无线网卡,所以要指定 #判断是否连接成功 if iface.status() in [const.IFACE_CONNECTED,const.IFACE_INACTIVE]: print('wifi已连接') return 0 else: print('wifi未连接') return 1 def connect_wifi(): wifi = pywifi.PyWiFi() # 创建一个wifi对象 ifaces = wifi.interfaces()[0] # 取第一个无限网卡 ifaces.disconnect() # 断开网卡连接 time.sleep(3) # 缓冲3秒
profile = pywifi.Profile() # 配置文件
profile.ssid = "802.1x" # wifi名称
ifaces.remove_all_network_profiles() # 删除其他配置文件
tmp_profile = ifaces.add_network_profile(profile) # 加载配置文件
ifaces.connect(tmp_profile) # 连接
time.sleep(6) # 尝试6秒能否成功连接
if ifaces.status()==const.IFACE_CONNECTED:
print("802.1x连接成功")
else:
print("802.1x连接失败")
def get_wifi_name(): status, output =subprocess.getstatusoutput("netsh WLAN show interfaces") if output.find("802.1x")!=-1: print("当前连接的wifi是802.1x") return 0 else: print("当前连接的wifi不是802.1x") return 1 def con801(): if(wifi_connect_status()==1): connect_wifi() else: if(get_wifi_name()==1): connect_wifi() while True: con801() time.sleep(10)
//https://blog.csdn.net/xiaoxianerqq/article/details/81279425 //密码方式: profile.akm.append(const.AKM_TYPE_WPA2) # wifi加密算法 profile.cipher = const.CIPHER_TYPE_CCMP # 加密单元 profile.key = pwd # 密码
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有