"""主代碼 ""
import settings
import paramiko
import threading
class wang(object):
def __init__(self, host, port, username, password, cmd):
self.host = host
self.port = port
self.username = username
self.password = password
self.cmd = cmd
def commad(self):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=self.host, port=self.port, username=self.username, password=self.password)
stdin, stdout, stderr = ssh.exec_command(self.cmd)
res, err = stdout.read(), stderr.read()
result = res if res else err
print(result.decode())
ssh.close()
def show_group():
for index, key in enumerate(settings.msg_dic):
print(index +1 , key, len(settings.msg_dic[key]))
host_ip = input(">>(eg:group1)").strip()
host_ip_drt = settings.msg_dic[host_ip]
print(host_ip_drt)
for i in host_ip_drt:
print(i, host_ip_drt[i]["IP"])
return host_ip_drt
def run():
setsit = show_group()
thread_list = []
print(setsit)
while True:
cmd = input(">>(cmd)").strip()
for i in setsit:
cc = wang(setsit[i]["IP"], setsit[i]["port"], setsit[i]["username"], setsit[i]["password"], cmd)
#cc.commad()
t = threading.Thread(target=cc.commad)
t.start()
thread_list.append(t)
print("-"*50)
for t in thread_list:
t.join()
print("-" * 50)
run()
#settings 模塊
msg_dic = {
"group1":{
"h2" :{"IP": "192.168.3.200", "username": "root", "password": "sadmin", "port": "22"},
"h3" :{"IP": "192.168.3.201", "username": "root", "password": "sadmin", "port": "22"}
}
"group2":{
"h2" :{"IP": "192.168.3.203", "username": "root", "password": "sadmin", "port": "22"},
"h3" :{"IP": "192.168.3.204", "username": "root", "password": "sadmin", "port": "22"}
}
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
成都創(chuàng)新互聯(lián)是專業(yè)的石家莊網(wǎng)站建設(shè)公司,石家莊接單;提供網(wǎng)站設(shè)計(jì)制作、網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行石家莊網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
當(dāng)前文章:python操作多臺(tái)服務(wù)器-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://aaarwkj.com/article10/ccdogo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄、建站公司、網(wǎng)站改版、搜索引擎優(yōu)化、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容