欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

Python密码生成器

发布时间:2023/12/31 python 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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 i 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'     p = PASSWORD(length, fname_iplist, fname_password)     p.CreatePassword()     p.DisplayPassword()









本文转自 wangpengtai  51CTO博客,原文链接:http://blog.51cto.com/wangpengtai/1943714,如需转载请自行联系原作者

总结

以上是生活随笔为你收集整理的Python密码生成器的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。