python實現(xiàn)linux服務器批量修改密碼并生成execl
批量修改linux服務器密碼,同時生成execl表格
#!/usr/bin/env python
#coding:utf8
#隨機生成自定義長度密碼
from random import choice
import string,pickle
def GenPassword(length=8,chars=string.ascii_letters+string.digits):
return ''.join([choice(chars) for i in range(length)])
def passlist(r_user,c_user,ip_list,web_list):
dic={}
for i in ip_list:
if i.split()[1] in web_list:
dic[i.split()[1]]=[i.split()[0],{r_user:GenPassword(32),c_user:GenPassword(32)}]
else:
dic[i.split()[1]]=[i.split()[0],{r_user:GenPassword(32)}]
return dic
def ip_list(ip_file):
with open(ip_file) as file:
ip_file=file.read().strip().split("\n")
#web_list=[i for i in ip_file if i in web_list]
return ip_file
def save_dic():
dic=main()
with open("../host_message.pickle","w") as fd:
pickle.dump(dic,fd)
def main():
file="/root/cui/script/python/ip.txt"
web_list=[ip1,ip2,ip3,ip4]
file_list=ip_list(file)
file_dic_pass=passlist("root","www",file_list,web_list)
return file_dic_pass
if __name__=="__main__":
save_dic()
#!/usr/bin/env python
#coding:utf8
#批量修改密碼主程序
import pickle
from ssh_co.ssh_connect import sshd
from command.ip_passwd import save_dic,main
from execl import set_execl
def read_dic():
with open("host_message.pickle","rb") as f:
return pickle.load(f)
def ssh_main():
pid_host=1
host_message=read_dic()
host_list=host_message.keys()
print host_list
for host_msg in xrange(len(host_list)):
host_attribute=(host_list[host_msg],port,user,passwd)
ssh_conn=sshd(host_attribute,pid_host)
if "www" in host_message[host_list[host_msg]][1].keys():
for username in xrange(len(host_message[host_list[host_msg]][1].keys())):
try:
user=host_message[host_list[host_msg]][1].keys()[username]
passwd=host_message[host_list[host_msg]][1][host_message[host_list[host_msg]][1].keys()[username]]
results=ssh_conn.set_ssh_cmd(u"/bin/echo %s|/usr/bin/passwd --stdin %s" %(passwd,user))
print results,host_list[host_msg],user+"-----------"+passwd
except:
print results,host_list[host_msg],user+"-----except------"+passwd
else:
user=host_message[host_list[host_msg]][1].keys()[0]
passwd=host_message[host_list[host_msg]][1][host_message[host_list[host_msg]][1].keys()[0]]
result=ssh_conn.set_ssh_cmd(u"/bin/echo %s|/usr/bin/passwd --stdin %s" %(passwd,user))
print result,host_list[host_msg],user+"-----------"+passwd
if __name__ == "__main__":
dic=main()
with open("host_message.pickle","w") as fd:
pickle.dump(dic,fd)
set_execl()
ssh_main()
相關文章
pytorch中節(jié)約顯卡內(nèi)存的方法和技巧
顯存不足是很多人感到頭疼的問題,畢竟能擁有大量顯存的實驗室還是少數(shù),而現(xiàn)在的模型已經(jīng)越跑越大,模型參數(shù)量和數(shù)據(jù)集也越來越大,所以這篇文章給大家總結(jié)了一些pytorch中節(jié)約顯卡內(nèi)存的方法和技巧,需要的朋友可以參考下2023-11-11使用python Telnet遠程登錄執(zhí)行程序的方法
今天小編就為大家分享一篇使用python Telnet遠程登錄執(zhí)行程序的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-01-01Python 200行代碼實現(xiàn)一個滑動驗證碼過程詳解
這篇文章主要介紹了Python 200行代碼實現(xiàn)一個滑動驗證碼過程詳解,各種各樣的驗證碼,比較高級的有滑動、點選等樣式,看起來好像挺復雜的,但實際上它們的核心原理還是還是很清晰的,本文章大致說明下這些驗證碼的原理以及帶大家實現(xiàn)一個滑動驗證碼2019-07-07用Python創(chuàng)建簡易網(wǎng)站圖文教程
今天給大家?guī)淼氖顷P于Python的相關知識,文章圍繞著用Python創(chuàng)建簡易網(wǎng)站展開,文中有非常詳細的介紹及圖文示例,需要的朋友可以參考下2021-06-06Python實現(xiàn)圖片格式轉(zhuǎn)換小程序
這篇文章主要為大家詳細介紹了Python實現(xiàn)圖片格式轉(zhuǎn)換小程序,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-08-08