京公网安备 11010802034615号
经营许可证编号:京B2-20210330
程序执行时需要读取两个文件command.txt和ipandpass.txt。格式如下:
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:
print threading.currentThread().getName(),'i quit,the queue is empty'
break
except Exception, error:
print error
class ThreadPool:
def __init__(self, num_of_threads=10):
self.workQueue = Queue.Queue()
self.threads = []
self.__createThreadPool(num_of_threads)
#create the threads pool
def __createThreadPool(self, num_of_threads):
for i in range(num_of_threads):
thread = MyThread(self.workQueue)
self.threads.append(thread)
def wait_for_complete(self):
#print len(self.threads)
while len(self.threads):
thread = self.threads.pop()
if thread.isAlive():
thread.join()
def add_job(self, callable, username, password, ipAddress, Port,comms):
self.workQueue.put((callable, username, password, ipAddress, Port,comms))
def uploadAndExecu(usernam,password,hostname,port,comm):
print usernam,password,hostname,port,comm
try:
t = paramiko.Transport((hostname,int(port)))
t.connect(username=username,password=password)
sftp=paramiko.SFTPClient.from_transport(t)
sftp.put(comm['local_dir'],comm['remote_dir'])
except Exception,e:
print 'upload files failed:',e
t.close()
finally:
t.close()
try:
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
ssh.connect(hostname, port=int(port), username=username, password=password)
ssh.exec_command(comm['alter_auth'])
ssh.exec_command(comm['exec_program'])
except Exception,e:
print 'chang file auth or execute the file failed:',e
ssh.close()
def readConf():
comm={}
try:
f = file('command.txt','r')
for l in f:
sp = l.split(':')
comm[sp[0]]=sp[1].strip('\n')
except Exception,e:
print 'open file command.txt failed:',e
f.close()
return comm
if __name__ == "__main__":
commandLine = readConf()
print commandLine
#prepare the ips
wm = ThreadPool(int(commandLine['ThreadNum']))
try:
ipFile = file('ipandpass.txt','r')
except:
print "[-] ip.txt Open file Failed!"
sys.exit(1)
for line in ipFile:
IpAdd,username,pwd = line.strip('\r\n').split(' ')
wm.add_job(uploadAndExecu,username,pwd,IpAdd,commandLine['port'],commandLine)
数据分析咨询请扫描二维码
若不方便扫码,搜微信号:CDAshujufenxi
CDA数据分析师 出品 作者:李诗怡 1. IF:基础条件判断(最常用) 作用:根据指定条件的真(TRUE)或假(FALSE),返回两种不同 ...
2026-10-30“不限专业可以考的证书”这个搜索词背后,通常藏着一个很实际的担心:专业不对口,想考个证拓宽出路,但怕报了名才发现有专业限 ...
2026-10-30先回答:能考的多是技能实操类证书 40岁、初中学历,能报的证书主要集中在四类:职业技能等级证书、专项职业能力证书、特种作业 ...
2026-10-3030岁考什么证好找工作,没有一张“通用答案”。同样的证书,对有行业经验的人和准备跨行的人,价值完全不同。更实际的思路是:先 ...
2026-10-30“专业职业技术资格证书”并不是一个正式名称,而是把好几种证书混在一起的口语说法。有人用它指会计、经济这类职称考试,有人指 ...
2026-10-30大学生能考的证书,大致分四类:通用基础类、职业资格类、专业技术资格类、岗位技能与行业认证类。真正要解决的问题不是“还有哪 ...
2026-10-30“需要考哪些证书”这个问题,没有统一答案。因为“需要”至少分三种:有的证书是入职准入,没有它连岗位门槛都进不去;有的证书 ...
2026-10-30“现在什么证含金量高好考一些”,这个问题里其实藏着两个容易打架的条件。含金量高的证书,往往有报考门槛、考试周期长;好考的 ...
2026-10-30“现在考什么证最吃香”,这个问题本身藏着一个容易踩的坑:不同人说“吃香”,指的往往不是同一件事。有人指考的人多、话题热; ...
2026-10-30文凭低,不等于没证可考,但选择空间确实窄一些。学历门槛明确的准入类资格,比如部分教师资格、法律职业资格、执业医师等,通常 ...
2026-10-30土建专业的大学生问“考什么证”,最容易踩的坑是把注册类证书当成在校目标。注册建造师、注册造价工程师、注册结构工程师、监理 ...
2026-10-30中年男人考证书,最怕两件事:一是年龄、学历卡在报名门槛外,白准备半年;二是考完发现岗位用不上,钱和时间都打了水漂。所以顺 ...
2026-10-30大专学历能考的证书不少,但真正值得投入时间的,是先确认“能不能报”,再看“考了对应什么岗位”。很多证书的报考条件里写着本 ...
2026-10-30“十大建议考的证书”这个问题,很难有一份对所有人都成立的名单。同一张证书,对会计专业大三学生、想转行做数据分析的运营、以 ...
2026-10-30“什么证书有用含金量高”这个问题,很难用一张榜单回答。同一本证书,对想进医院的人可能是硬门槛,对做运营的人却用不上;对已 ...
2026-10-30在职成年人问“考什么证书有用”,先要弄清自己需要哪一种“有用”。同一张证书,对想进入准入行业的人、想在本岗晋升的人、想转 ...
2026-10-30“女生能考的证书”真正要先回答的是“你现在的条件能报什么”。学历、专业、工作年限、是否在校、所在地区政策,直接决定你能不 ...
2026-10-30“女孩考什么证书比较好”这句话里,“比较好”其实藏着三种完全不同的标准:好考,看的是报考门槛低、备考周期短;好就业,看的 ...
2026-10-30先给结论:市场岗位没有一张通吃的证书。品牌传播、数字营销与投放、用户增长、用户研究、营销数据分析,这五条路径对应的工作任 ...
2026-10-30经济学专业考什么证书,没有统一答案。经济学毕业后去向很散:有人进银行、证券、基金,有人做财务审计,有人转数据分析与经营分 ...
2026-10-30