Python 多线程密码字典生成脚本 - 高效生成密码字典
import threading
import string
# 定义一个生成字典的函数
def GenerateDict(length, charset):
result = []
if length == 0:
return ['']
for char in charset:
# 对每个字符,生成比它短一个字符的字典
sub_dict = GenerateDict(length - 1, charset)
# 将该字符拼接到每个字典的每个字符串后面
for s in sub_dict:
result.append(s + char)
return result
# 定义一个保存字典的函数
def SaveDict(dict_list):
with open('dict.txt', 'a+') as f:
for i in dict_list:
f.write(i + '\n')
# 定义一个线程类
class MyThread(threading.Thread):
def __init__(self, length, charset):
threading.Thread.__init__(self)
self.length = length
self.charset = charset
# 重写run函数
def run(self):
dict_list = GenerateDict(self.length, self.charset)
SaveDict(dict_list)
# 定义一个主函数
def main():
# 定义密码字典长度
length = 8
# 定义密码字典字符集
charset = string.ascii_letters + string.digits
# 创建线程池
thread_pool = []
for i in range(length):
thread_pool.append(MyThread(i + 1, charset))
# 启动线程
for t in thread_pool:
t.start()
# 等待所有线程执行结束
for t in thread_pool:
t.join()
if __name__ == '__main__':
main()
本脚本利用多线程技术,可以快速生成大量的密码组合,并将它们保存到一个名为 'dict.txt' 的文本文件中。你可以根据需要修改脚本中的 length 和 charset 参数来生成不同长度和字符集的密码字典。
使用方法:
- 复制脚本代码到一个 Python 文件中(例如
password_generator.py)。 - 运行该文件。
- 在脚本所在的目录中会生成一个名为
dict.txt的文件,其中包含生成的密码组合。
注意:
- 生成大量的密码字典会占用大量的磁盘空间。
- 使用生成的密码字典进行暴力破解是非法的,请勿用于任何非法活动。
本脚本仅供学习和研究之用,请勿用于任何非法活动。
相关链接:
原文地址: https://www.cveoy.top/t/topic/lh2P 著作权归作者所有。请勿转载和采集!