第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

python paramiko多線程遇到的問(wèn)題

python paramiko多線程遇到的問(wèn)題

森林海 2019-02-24 03:59:08
最近在學(xué)習(xí)python,用python寫了個(gè)檢查ssh存活的腳本。寫完后想增加多線程功能,加快效率,可是一直報(bào)錯(cuò),麻煩大神幫我看下到底錯(cuò)在哪了 以下是代碼: #!/usr/bin/python import os import string import paramiko import traceback import threading class SshServerCMD(): def __init__(self): print 'start' self.username = 'root' self.passwd = '123' self.cmd = 'date +%s' self.ssh = paramiko.SSHClient() self.pass_file = '/opt/scripts/etc/ssh_proxy.conf' self.paramiko_log= '/tmp/check_ssh_proxy.log' self.threads = [] HostList = open(self.pass_file) for line in HostList.readlines(): ARAY_line = string.split(line) self.host = ARAY_line[0] self.port = int(ARAY_line[1]) self.t = threading.Thread(target = self.Connect,args = (self.host,self.port,self.username,self.passwd)) self.threads.append(self.t) for i in range(10): self.threads[i].start() for i in range(10): self.threads[i].join() def Connect(self,host,port,username,passwd): # This function is to connect the agent self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #ssh.load_system_host_keys() paramiko.util.log_to_file(self.paramiko_log) try: self.ssh.connect(host,port,username,passwd) except Exception as e: print '\033[31m' + self.host,str(e) + '\033[0m' else: self.Cmd() self.ssh.close() def Cmd(self): stdin,stdout,stderr = self.ssh.exec_command(self.cmd) self.sout = stdout.readlines() print '\033[32m' + self.host,str(self.sout) + '\033[0m' if __name__ == '__main__': SshServerCMD() 以下是/opt/scripts/etc/ssh_proxy.conf文件內(nèi)容 192.168.1.2 4001 192.168.1.3 4002 192.168.1.4 4003 192.168.1.5 4004 192.168.1.6 4005 192.168.1.7 4006 192.168.1.8 4007 192.168.1.9 4008 192.168.1.10 4009 192.168.1.11 4010 報(bào)錯(cuò):執(zhí)行腳本后,發(fā)現(xiàn)程序不停在嘗試ssh 192.168.1.11,也就是文本中所寫的最后一行的ip地址,并且全部都是連接失敗。在邏輯上我就想不通,就算是連接失敗,也應(yīng)該從第一行ip開(kāi)始嘗試,為什么會(huì)從最后一行ip開(kāi)始ssh呢?并且一直在嘗試ssh最后一行ip,求指教。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 686 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)