Python密码生成器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
密码生成器:
密码格式为:密码 + 空格 + 字符(随机产生自定义长度)
10.1 . 1.1  % V!Z{ #2)9G,-
10.1 . 1.2  xWIg; 9zIdn ?}
10.1 . 1.3  )PRRQiKU@oCj
10.1 . 1.4  sX<_?Z.<yd9&
10.1 . 1.5  Y{Zy[ym6z.,O
10.1 . 1.6  [qbXiBt37Rcu
10.1 . 1.7  )Xs7t6[^NlDP
10.1 . 1.8  H4CwO!!W8fAZ
10.1 . 1.9  #;VXI4lgawIx
10.1 . 1.10  e + 6VM &KTEb|"
直接将其写到文件里面,打开即可以使用了,一整行都是密码!为了方便初次部署salt批量生成salt - ssh的roster文件时候使用
 
 
 
# /usr/bin/env python
# __*__coding:utf8__*__
import  string
import  random
class  PASSWORD( object ):
     def  __init__( self ,length,fname_iplist,fname_password):
         self . len  =  length
         self .fname_iplist  =  fname_iplist
         self .fname_password  =  fname_password
     def  CreatePassword( self ):
         iplist  =  []
         password  =  []
         letters  =  string.digits  +  string.ascii_letters  +  '!@#$%^&*()_+-=|}{[];",<>.?/'
         file  =  open ( self .fname_iplist, 'r' )
         for  ip  in  file .readlines():
             iplist.append(ip.strip()  +  ' ' )
         file .close()
         #print iplist
         for  ip  in  iplist:
             #print ip
             #print len(ip)
             password.append(ip)
             if  self . len  -  len (ip) < =  0 :
                 print  "密码长度不能低于ip自身长度!"
                 exit()
             else :
                 for  in  range ( self . len - len (ip)):
                     password.append(random.choice(letters))
                 password.append( '\n' )
         # print password
         password_list  =  ' '.join(password).split(' \n')
         # print password_list
         file  =  open ( self .fname_password, 'wb+' )
         for  line  in  password_list:
             #print line
             file .write(line  +  '\n' )
         file .close()
     def  DisplayPassword( self ):
         file  =  open ( self .fname_password, 'r' )
         print
         print  "以下为密码列表:"
         for  line  in  file .readlines():
             print  line,
         file .close()
if  __name__  = =  "__main__" :
     try :
         length  =  int ( raw_input ( '输入密码长度(建议密码长度为45到255之间):' ))
         if  length >  255 :
             print  "密码长度超过255,改为默认长度45"
             length  =  45
     except  ValueError:
         print  "输入正确的数字不是整数,改为默认长度45"
         length  =  45
     fname_iplist  =  '/tmp/iplist.txt'
     fname_password  =  '/tmp/password.txt'
     =  PASSWORD(length, fname_iplist, fname_password)
     p.CreatePassword()
     p.DisplayPassword()









本文转自 wangpengtai  51CTO博客,原文链接:http://blog.51cto.com/wangpengtai/1943714,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值