国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用paramiko模塊實現ssh遠程登陸上傳文件并執行

2020-02-23 05:08:29
字體:
來源:轉載
供稿:網友

程序執行時需要讀取兩個文件command.txt和ipandpass.txt。格式如下:

代碼如下:
command.txt:
ThreadNum:1
port:22
local_dir:hello_mkdir
remote_dir:hello_mkdir
alter_auth:chmod 755 hello_mkdir
exec_program:./hello_mkdir

ipandpass.txt:
ip username password

程序中的隊列操作是修改的別的程序,寫的確實不錯。
該程序亦正亦邪,如果拿去做壞事,我先聲明與我無關,我只是分享我的代碼罷了。
希望有興趣的同志們來討論技術應用。
這其中用到了paramiko,隊列,多線程,后續也會寫一些這三個方面的東西。歡迎批評指正。
其實這個程序有些地方還有待優化。

代碼如下:
#function:upload files through ssh protocal and excute the files
#lib:paramiko
#MyThread:init a thread to run the function
#ThreadPol:init a thread pool
#uploadAndExecu:upload file and excute
#readConf:read config file
#-*- coding = utf-8 -*-


import Queue
import sys
import threading
import paramiko
import socket
from threading import Thread
import time

class MyThread(Thread):
    def __init__(self, workQueue, timeout=1):
        Thread.__init__(self)
        self.timeout = timeout
        self.setDaemon(False)
        self.workQueue = workQueue
        self.start()
        #print 'i am runnning ...'

    def run(self):
        emptyQueue = 0
        while True:
            try:
                callable, username, password, ipAddress, port,comms = self.workQueue.get(timeout = self.timeout)
                #print 'attacking :',ipAddress,username,password,threading.currentThread().getName(),' time : '
                callable(username,password, ipAddress, port,comms)

            except Queue.Empty:
                print threading.currentThread().getName(),":queue is empty ; sleep 5 seconds/n"
                emptyQueue += 1
                #judge the queue,if it is empty or not.
                time.sleep(5)
                if emptyQueue == 5:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 林州市| 玛曲县| 茌平县| 万荣县| 定日县| 柞水县| 西青区| 琼海市| 莱西市| 景谷| 嘉鱼县| 石景山区| 历史| 巨野县| 图木舒克市| 大渡口区| 陕西省| 辽宁省| 盐津县| 六盘水市| 和静县| 琼结县| 郯城县| 友谊县| 阳曲县| 鹤庆县| 长宁区| 南江县| 肃南| 惠安县| 旺苍县| 出国| 兴义市| 台东市| 大名县| 广安市| 于都县| 都兰县| 宕昌县| 光山县| 石景山区|