一个Python写的字典生成器
汗颜自己简单改了下,还在学习Python中~~! 大家可以自由选择生成密码的长度和生成密码的组合,有四种组合,数字、小写字母、大小字母、数字+大小写字母+特殊符号!使用方法“zidian.py all 8 10 -w test.txt”
代码:
[python]
#!/usr/bin/python
# -*- coding:utf-8 -*-
#字典生成器,可以按密码类型生成指定长度的密码和数量
#密码类型: alphanum(数字), alpha(小写字母), alphacap(大写字母), all(数字+大小写字母+特殊符号)
#http://huairen.me
import random, sys
def title():
print “\n\t Huairen.Me Password dict ”
print “\t———————————————–\n”
def passgen(choice, length):
passwd = “”
alphanum = (‘0123456789’)
alpha = (‘abcdefghijklmnopqrstuvwxyz’)
alphacap = (‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’)
all = (‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~[]{}|\:;"\’<>,.?/’)
if str(choice).lower() == “alphanum”:
choice = alphanum
elif str(choice).lower() == “alpha”:
choice = alpha
elif str(choice).lower() == “alphacap”:
choice = alphacap
elif str(choice).lower() == “all”:
choice = all
else:
print “请选择密码类型\n”
sys.exit(1)
return passwd.join(random.sample(choice, int(length)))
title()
if len(sys.argv) <= 3 or len(sys.argv) == 5:
print “\n\t 使用说明”
print “\n\t Demo:zidian.py all 8 50 -w zidian.txt \n”
print “\n\t Http://Huairen.Me”
print “\t———————————————–\n”
sys.exit(1)
for arg in sys.argv[1:]:
if arg.lower() == “-w” or arg.lower() == “-write”:
txt = sys.argv[int(sys.argv[1:].index(arg))+2]
if sys.argv[3].isdigit() == False:
print sys.argv[3],”必须是一个数字\n”
sys.exit(1)
if sys.argv[2].isdigit() == False:
print sys.argv[2],”必须是一个数字\n”
sys.exit(1)
try:
if txt:
print “[+] 生成文件:”,txt
output = open(txt, “a”)
except(NameError):
txt = None
pass
for x in xrange(int(sys.argv[3])):
if txt != None:
output.writelines(passgen(sys.argv[1],sys.argv[2])+”\n”)
else:
print “Password:”,passgen(sys.argv[1],sys.argv[2])
print “\n[-] 生成完成\n”
[/python]
没有评论
暂无评论
RSS feed for comments on this post.
对不起,该文章的评论被关闭了!