Python密碼生成器
阿新 • • 發佈:2017-07-01
密碼 python 生成器
密碼生成器: 密碼格式為:密碼+空格+字符(隨機產生自定義長度) 10.1.1.1 %V!Z{#2)9G,- 10.1.1.2 xWIg;9zIdn?} 10.1.1.3 )[email protected] 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,len, fname_iplist, fname_password): self.len = len 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.replace(‘\n‘, ‘ ‘)) file.close() for ip in iplist: # print ip password.append(ip) for i in range(self.len): 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‘) for line in file.readlines(): print line file.close() if __name__ == "__main__": len = int(raw_input(‘輸入密碼長度:‘)) fname_iplist = ‘/home/wangpengtai/Desktop/iplist.txt‘ fname_password = ‘/home/wangpengtai/Desktop/password.txt‘ p = PASSWORD(len, fname_iplist, fname_password) p.CreatePassword() p.DisplayPassword()
本文出自 “LINUX” 博客,請務必保留此出處http://wangpengtai.blog.51cto.com/3882831/1943714
Python密碼生成器