#!/usr/bin/env python
#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


如果想了解更多,请关注我们的公众号
公众号ID:opdevos
扫码关注

随机密码生成器_第1张图片