python gui 之熟悉tkinter部分控件使用。一个简单的excel暴力密码破解,核心很简单,基本就是一个函数外面加了GUI,写的很啰嗦,希望大家可以在优化改良下,主要是为了再熟悉下tkinter的部分控件怎么使用,tk打包后的文件比较小。仅限于个人忘记密码时使用,请勿用于其它用途。如想转载,请联系本人,或贴上本博客地址。

程序截图如下:

import os,sys,subprocess
from tkinter import *
import socket
import threading
import time
import queue
import tkinter.messagebox as msgbox
import win32com.client
#多线程调用win32com模块打开excel,报错,加下面
import pythoncom
import tkinter as tk
from tkinter import ttk
from tkinter import *
from tkinter import scrolledtext
#选择文件
from tkinter import filedialog #窗体居中
def center_window(root, width, height):
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
#print(size)
root.geometry(size) class MyGui():
def __init__(self, init_window_name):
self.init_window_name = init_window_name def set_init_window(self): #初始化窗口
self.k = 0
self.init_window_name.title("excel密码破解")
self.window_center(390, 350)
self.init_window_name.resizable(0,0) #固定窗口,禁止拖拉 #参数是父级控件
self.menubar = Menu(self.init_window_name)
#新增2个级联菜单
self.cascadehelp=Menu(self.menubar,tearoff=False)#tearoff=False 表示这个菜单不可以被拖出来
self.cascadeabout=Menu(self.menubar,tearoff=False)#tearoff=False 表示这个菜单不可以被拖出来
#向父控件添加help级联菜单
self.menubar.add_cascade(label='帮助', menu = self.cascadehelp)
#级联菜单增加选项
self.cascadehelp.add_command(label='使用说明',command = self.howuse)
self.menubar.add_cascade(label='关于', menu = self.cascadeabout)
self.cascadeabout.add_command(label='关于本工具',command = self.about)
self.init_window_name.config(menu = self.menubar) self.frame_top = Frame(self.init_window_name, width=390, height=350,borderwidth = 1,bd=2,bg='lightgreen')
self.frame_top.grid(row=0, column=0)
self.PortScan = ttk.Button(self.frame_top, text="立即破解", command= self.runing).grid(row=4, column=1)
#停止
self.StopScan = ttk.Button(self.frame_top, text="停止破解",command=self.stop).grid(row=4, column=2)
self.select_path = tk.StringVar()
# 初始化Label控件的textvariable属性值
self.select_dic_path = tk.StringVar()
# 布局控件
tk.Label(self.frame_top, text="文件路径:",bg='lightgreen').grid(column=0, row=0)#columnspan和rowspan分别可以设置控件在行和列方向的合并数量
tk.Entry(self.frame_top, textvariable = self.select_path).grid(column=1, row=0)
ttk.Button(self.frame_top, text="选择单个文件", command=self.select_file).grid(row=0, column=2)
#指定数字位数
tk.Label(self.frame_top, text="指定密码位数:",bg='lightgreen').grid(column=0, row=1)
self.feet = StringVar()
feet_entry = ttk.Entry(self.frame_top, width=3, textvariable=self.feet).grid(column=1, row=1,sticky=(W))#sticky=(W)左对齐, sticky=(W, E))左右对齐,控件占满行列
#feet_entry.bind('', self.keyPress)
tk.Label(self.frame_top, text="(可不填,默认0开始)",bg='lightgreen').grid(column=2, row=1,sticky=(W))
#选择字典文件
ttk.Button(self.frame_top, text="选择字典文件", command=self.select_dic).grid(row=3, column=0)
tk.Entry(self.frame_top, textvariable = self.select_dic_path,bg='lightgreen').grid(column=1, row=3)
#历史记录
scrolW = 30; scrolH = 16
scr = scrolledtext.ScrolledText(width=scrolW, height=scrolH, wrap=tk.WORD) #monty,
scr.grid(column=0, row=1, sticky='WE', columnspan=1)
scr.config(state=DISABLED)
for child in self.frame_top.winfo_children(): child.grid_configure(padx=3, pady=3) # padx表示在x轴方向上的边距,一般用法是padx=10,表示距离左右两边组件的长度都为10 def about(self):
messagebox.showinfo('关于','欢迎使用本工具,本工具开源免费,仅限于个人忘记密码时使用,请勿用于商业用途。')
def close_handler(self):
# 在colse_handler函数中,使得父窗口重新变得可用
self.init_window_name.attributes('-disabled', 0)
def howuse(self):
help_text1 = '1、破解数字密码,可直接选择文件,点击 “立即破解”,如果直接数字密码大概是几位,可以指定密码位数,可加快破解效率。'
help_text2 = '2、如有常用密码的txt字典,可选择文件,再选择字典文件,点击“立即破解”。'
top = Toplevel()
top.title('使用帮助')
#顶级窗口也屏幕居中显示
center_window(top,700,60)
#窗口置顶
top.wm_attributes('-topmost',1)
top.resizable(0,0) #固定窗口,禁止拖拉
tk.Label(top, text=help_text1).grid(row=1,column=1,padx=1,pady=1)
tk.Label(top, text=help_text2).grid(row=2,column=1,padx=1,pady=1,sticky=(W)) #左对齐 # 窗口居中
def window_center(self, width, height):
screenwidth = self.init_window_name.winfo_screenwidth()
screenheight = self.init_window_name.winfo_screenheight()
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
self.init_window_name.geometry(size) # 获取当前时间
def get_current_time(self):
current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
return current_time # 单个文件选择
#指定文件类型
def select_file(self):
# 使用askopenfilename函数选择单个文件
selected_file_path = filedialog.askopenfilename(title='选择表格文件',
filetypes=[('All Files', '*'),
('表格', '*.xlsx')])
self.select_path.set(selected_file_path) #选择字典文件
def select_dic(self):
selected_dic = filedialog.askopenfilename(title='选择字典文件',
filetypes=[('All Files', '*'),
('txt', '*.txt')])
self.select_dic_path.set(selected_dic) class MyThread(threading.Thread):
def __init__(self, func, *args):
super().__init__() self.func = func
self.args = args self.setDaemon(True)
self.start() #开始 def run(self):
self.func(*self.args) def stop(self):
self.k = 0
msgbox.showinfo(title='提示', message='停止破解。')
ttk.Button(self.frame_top, text="立即破解", command= self.runing).grid(row=4, column=1) def runing(self):
pythoncom.CoInitialize()
if self.select_path.get() =='':
msgbox.showinfo(title="提示", message="请先选择文件!")
else:
ttk.Button(self.frame_top, text="立即破解", command= self.runing, state=tk.DISABLED).grid(row=4, column=1)#, padx=15, pady=20)
self.k = 1
self.MyThread(self.get_sheetpw) def get_sheetpw(self):
pythoncom.CoInitialize()
cmdwps ='taskkill /F /IM wps.exe'
cmdexcel = 'taskkill /F /IM EXCEL.exe'
p = subprocess.Popen(cmdwps)
p.wait()
p2 = subprocess.Popen(cmdexcel)
p2.wait() #历史记录
scrolW = 30; scrolH = 16
scr = scrolledtext.ScrolledText(width=scrolW, height=scrolH, wrap=tk.WORD) #monty,
scr.grid(column=0, row=1, sticky='WE', columnspan=1)
scr.config(state=DISABLED)
for child in self.frame_top.winfo_children(): child.grid_configure(padx=3, pady=3)
file_path = self.select_path.get()
dic_path = self.select_dic_path.get()
print(file_path)
try:
xls = win32com.client.Dispatch("Excel.Application")
except:
xls = win32com.client.Dispatch("ket.Application")
xls.DisplayAlerts=0 if dic_path!='':
with open(dic_path,'r',encoding='utf-8') as f:
flag=0
for i in f.readlines():
print('破解中......')
start_time = time.time()
if self.k == 1:
try:
xlsheet = xls.Workbooks.Open(file_path, False, True, None, Password=i.strip())
print('破解成功!')
print("文档密码是:{}".format(i.strip()))
xlsheet.Close()
end_time = time.time()
use_time = end_time - start_time
use_time = round(use_time,2)
print('共耗时:' + str(use_time) +'秒')
flag=1
msgbox.showinfo(title="提示", message="破解成功!excel密码是:%s。共耗时: %s秒" %(i.strip(),use_time))
ttk.Button(self.frame_top, text="立即破解", command= self.runing).grid(row=4, column=1)
break
#return True
except Exception as e:
print('完成一次,'+'当前测试的密码是'+ str(i.strip()))
info = '完成一次,当前测试的密码是'+ str(i.strip())
scr.config(state=NORMAL)
value = info
value=value.replace("'\n'","")
oldvalue=scr.get(0.0,tk.END)
delvalue=scr.delete(0.0,tk.END)
scr.insert(tk.INSERT,value +'\n'+oldvalue)
scr.config(state=DISABLED)
if flag==0:
msgbox.showinfo(title="提示", message='破解失败,此字典未破解出密码!')
ttk.Button(self.frame_top, text="立即破解", command= self.runing).grid(row=4, column=1)
else:
num = int(self.feet.get()) if self.feet.get()!='' else 0
#num = int(self.feet.get())
if num!='':
if int(num)==1:
p=0
elif int(num)==2:
p=10
elif int(num)==3:
p=100
elif int(num)==4:
p=1000
elif int(num)==5:
p=10000
elif int(num)==6:
p=100000
elif int(num)==7:
p=1000000
elif int(num)==8:
p=10000000
elif int(num)==9:
p=100000000
elif int(num)==10:
p=1000000000
elif int(num)==11:
p=10000000000
elif int(num)==11:
p=100000000000
elif int(num)==12:
p=1000000000000
else:
p=0
else:
p=0
print('破解中......')
start_time = time.time()
while True:
if self.k == 1:
try:
xlsheet = xls.Workbooks.Open(file_path, False, True, None, Password=p)
print('破解成功!')
print("文档密码是:{}".format(p))
xlsheet.Close()
end_time = time.time()
use_time = end_time - start_time
use_time = round(use_time,2)
print('共耗时:' + str(use_time) +'秒')
msgbox.showinfo(title="提示", message="破解成功!excel密码是:%s。共耗时: %s秒" %(p,use_time))
ttk.Button(self.frame_top, text="立即破解", command= self.runing).grid(row=4, column=1)#, padx=15, pady=20)
break
#return True
except Exception as e:
print('完成一次,'+'当前测试的密码是'+ str(p))
info = '完成一次,当前测试的密码是'+ str(p)
scr.config(state=NORMAL)
value = info
value=value.replace("'\n'","")
oldvalue=scr.get(0.0,tk.END)
delvalue=scr.delete(0.0,tk.END)
scr.insert(tk.INSERT,value +'\n'+oldvalue)
scr.config(state=DISABLED)
p=p+1
else:
breakpoint if __name__ == "__main__":
pygui=Tk()
#窗口置顶
pygui.wm_attributes('-topmost',1)
init_window = MyGui(pygui)
init_window.set_init_window()
pygui.mainloop()

python-GUI-tkinter之excel密码破解工具的更多相关文章

  1. [转]Linux下的暴力密码破解工具Hydra详解

    摘自:http://linzhibin824.blog.163.com/blog/static/735577102013144223127/ 这款暴力密码破解工具相当强大,支持几乎所有协议的在线密码破 ...

  2. 这款Office密码破解工具,无坚不摧!

    你是否曾经陷入过这样的尴尬:因为忘记Word文档密码去找了一个Word密码破解工具,接着又忘记Excel文档密码去找了一个专门破击Excel的工具,那么如果忘记PowerPoint.Outlook.P ...

  3. hydra 密码破解工具详解

    一.简介 hydra是著名黑客组织thc的一款开源的暴力密码破解工具,可以在线破解多种密码.官 网:http://www.thc.org/thc-hydra,可支持AFP, Cisco AAA, Ci ...

  4. Word密码破解工具字典攻击用来干什么的

    AOPR全称Advanced Office Password Recovery作为一款专业的Word密码破解工具,是通过暴力破解的方式帮助用户迅速恢复各种Word文档的密码,其中常常会用到字典攻击,这 ...

  5. Office密码破解工具最好用的是哪款

    很多的用户朋友设置密码的office文档一般都含有比较重要的信息.因此,忘记密码在破解的过程中非常重视安全保密性.现在有很多款office密码破解工具,很多的用户朋友不知道用哪一款比较好,其中Adva ...

  6. Python GUI - Tkinter tkMessageBox

    Python GUI - Tkinter tkMessageBox: tkMessageBox模块用于显示在您的应用程序的消息框.此模块提供了一个功能,您可以用它来显示适当的消息     tkMess ...

  7. Windows密码破解工具ophcrack

    Windows密码破解工具ophcrack   Windows用户密码都采用哈希算法加密进行保存.Kali Linux内置了专用破解工具ophcrack.该工具是一个图形化界面工具,支持Windows ...

  8. WEP/WPA-PSK密码破解工具aircrack-ng

    WEP/WPA-PSK密码破解工具aircrack-ng   aircrack-ng是Aircrack-ng工具集中的一个工具.该工具主要用于根据已经抓取的.cap文件或者.ivs文件破解出WEP/W ...

  9. linux暴力密码破解工具hydra安装与使用

    说明:hydra是著名黑客组织thc的一款开源的暴力密码破解工具,可以在线破解多种密码.官网:http://www.thc.org/thc-hydra,可支持AFP, Cisco AAA, Cisco ...

  10. 快讯 | FireEye在GitHub上开源密码破解工具GoCrack

    近日,FireEye 开源了一款密码破解工具 GoCrack,可在多机器上部署破解任务. GoCrack 是由 FireEye’s Innovation and Custom Engineering ...

随机推荐

  1. go-bindata安装问题

    问题描述使用命令 go get -u github.com/jteeuwen/go-bindata/... 报错: go get -u github.com/go-bindata/go-bindata ...

  2. 记录php遇到的那些坑

    首先按照网上指南搭建php.阿帕奇.数据库环境. 具体放上网站 http://www.cnblogs.com/ypr-09-23/p/10797153.html  这是mysql安装指南 需要注意的是 ...

  3. python爬取知乎的网站内容

    #获取知乎的网站内容 import requests #数据请求模块 第三方模块 pip install requests import re #正则表达式 #网页head头 heads = { 'U ...

  4. Python标准库模块之heapq

    创建堆 heapq有两种方式创建堆, 一种是使用一个空列表,然后使用heapq.heappush()函数把值加入堆中,另外一种就是使用heap.heapify(list)转换列表成为堆结构 #创建堆方 ...

  5. Oracle修改查询优化器版本

    查询优化器参数optimizer_features_enable 在每个数据库版本中,Oracle都会在查询优化器中引入或启用新的特性. 如果在升级到一个新的版本后希望保留查询优化器的行为,可以通过设 ...

  6. js 拖动图片

    <script type="text/javascript"> var oipc = document.getElementById('pic'); var isDra ...

  7. idea常用插件 自用

  8. macOS完整安装包下载方法

    Python脚本下载 开源地址:macadmin-scripts 下载installinstallmacos.py到Mac,然后用python运行,如图: #    ProductID    Vers ...

  9. BASE64编码作业

    BASE64编码作业 什么是BASE64编码 ase64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法.可查看RFC2045-RF ...

  10. SQL-分组聚合

    -- 语法 select * |列名|表达式         -- 5 from 表名                         -- 1 where 条件                    ...