#Author:Badboy
#Notice:set a few passwords, () will fill in for the item, [] is optional
from random import choice
import string
import sys
specialchars='!@#$%^&*()'
def GenPasswd(length,chars=string.letters+string.digits+specialchars):
return ''.join([choice(chars) for i in range(length)])
def usage():
usages='''
Usage:
./mkpass (password length) [password numbers]
Example:
./mkpass 14 [4]
'''
print usages,
if __name__=="__main__":
if len(sys.argv)==2:
print GenPasswd(int(sys.argv[1]))
elif len(sys.argv)==3:
for i in range(int(sys.argv[2])):
print GenPasswd(int(sys.argv[1]))
else:
usage()
执行结果图:
[root@test61 ~]# python mkpass.py
Usage:
./mkpass (password length) [password numbers]
Example:
./mkpass 14 [4]
[root@test61 ~]# python mkpass.py 15
$BkIZ1OIHGSV35#
[root@test61 ~]# python mkpass.py 15 6
@eT)hMXt)f%jPn$
aHrKisQj@PaJ9nf
NabrAJXZsG(SfHK
U9jqjHkyBW4eIO0
JH8T3RCWGFHMlW6
X9ezN^k5PbIpVvm
本文转自hahazhu0634 51CTO博客,原文链接:http://blog.51cto.com/5ydycm/349142,如需转载请自行联系原作者