"""主代碼 ""
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元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
成都創(chuàng)新互聯(lián)是專業(yè)的石家莊網(wǎng)站建設(shè)公司,石家莊接單;提供網(wǎng)站設(shè)計制作、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行石家莊網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!