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,如需转载请自行联系原作者
目录
相关文章
|
16天前
|
数据安全/隐私保护 Python
1178: 密码翻译(python)
1178: 密码翻译(python)
|
1月前
|
算法 大数据 Python
Python生成器:优雅而高效的迭代器
Python生成器:优雅而高效的迭代器
|
1月前
|
Python
请解释 Python 中的生成器的工作原理。
【2月更文挑战第20天】【2月更文挑战第58篇】请解释 Python 中的生成器的工作原理。
|
2月前
|
索引 Python 容器
解释Python中的迭代器和生成器的优势和劣势。
解释Python中的迭代器和生成器的优势和劣势。
33 2
|
1月前
|
Python
Python如何使用生成器生成更加优雅和高效的代码
Python如何使用生成器生成更加优雅和高效的代码
25 0
|
6天前
|
缓存 大数据 数据处理
Python迭代器、生成器和装饰器探究
【4月更文挑战第2天】 迭代器是遍历集合元素的对象,实现`__iter__()`和`__next__()`方法。示例中自定义迭代器`MyIterator`用于生成整数序列。 - 生成器简化了迭代器实现,利用`yield`关键词实现状态保存,减少内存占用。示例中的`my_generator`函数即为一个生成器。 - 装饰器用于修改函数行为,如日志记录、性能分析。装饰器`my_decorator`在函数调用前后添加额外代码。
23 0
|
7天前
|
大数据 数据处理 开发者
深入理解Python中的迭代器和生成器
Python中的迭代器和生成器是实现高效循环和处理大型数据集的重要工具。本文将深入探讨迭代器和生成器的概念、原理以及在实际开发中的应用场景,帮助读者更好地理解和利用这些强大的工具。
|
11天前
|
存储 大数据 Python
「Python系列」Python迭代器与生成器
Python迭代器是一个可以记住遍历的位置的对象。迭代器对象必须实现两个方法,`__iter__()` 和 `__next__()`。字符串、列表或元组等数据类型都是可迭代对象,但它们不是迭代器,因为它们没有实现 `__next__()` 方法。
13 0
|
16天前
|
安全 数据安全/隐私保护 Python
292: 程序设计C 实验五 题目三 设计密码(python)
292: 程序设计C 实验五 题目三 设计密码(python)
|
21天前
|
人工智能 机器人 测试技术
【Python】Python迭代器与生成器的区别(详细讲解)
【Python】Python迭代器与生成器的区别(详细讲解)
【Python】Python迭代器与生成器的区别(详细讲解)