京公网安备 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
数据库中的历史数据,是企业运营过程中沉淀的核心资产——包含用户行为轨迹、业务交易记录、产品迭代日志、市场活动效果等多维度 ...
2026-01-08在电商行业竞争日趋激烈的当下,数据已成为驱动业务增长的核心引擎。电商公司的数据分析师,不仅是数据的“解读官”,更是业务的 ...
2026-01-08在数据驱动决策的链路中,统计制图是CDA(Certified Data Analyst)数据分析师将抽象数据转化为直观洞察的关键载体。不同于普通 ...
2026-01-08在主成分分析(PCA)的学习与实践中,“主成分载荷矩阵”和“成分矩阵”是两个高频出现但极易混淆的核心概念。两者均是主成分分 ...
2026-01-07在教学管理、学生成绩分析场景中,成绩分布图是直观呈现成绩分布规律的核心工具——通过图表能快速看出成绩集中区间、高分/低分 ...
2026-01-07在数据分析师的工作闭环中,数据探索与统计分析是连接原始数据与业务洞察的关键环节。CDA(Certified Data Analyst)作为具备专 ...
2026-01-07在数据处理与可视化场景中,将Python分析后的结果导出为Excel文件是高频需求。而通过设置单元格颜色,能让Excel中的数据更具层次 ...
2026-01-06在企业运营、业务监控、数据分析等场景中,指标波动是常态——无论是日营收的突然下滑、用户活跃度的骤升,还是产品故障率的异常 ...
2026-01-06在数据驱动的建模与分析场景中,“数据决定上限,特征决定下限”已成为行业共识。原始数据经过采集、清洗后,往往难以直接支撑模 ...
2026-01-06在Python文件操作场景中,批量处理文件、遍历目录树是高频需求——无论是统计某文件夹下的文件数量、筛选特定类型文件,还是批量 ...
2026-01-05在神经网络模型训练过程中,开发者最担心的问题之一,莫过于“训练误差突然增大”——前几轮还平稳下降的损失值(Loss),突然在 ...
2026-01-05在数据驱动的业务场景中,“垃圾数据进,垃圾结果出”是永恒的警示。企业收集的数据往往存在缺失、异常、重复、格式混乱等问题, ...
2026-01-05在数字化时代,用户行为数据已成为企业的核心资产之一。从用户打开APP的首次点击,到浏览页面的停留时长,再到最终的购买决策、 ...
2026-01-04在数据分析领域,数据稳定性是衡量数据质量的核心维度之一,直接决定了分析结果的可靠性与决策价值。稳定的数据能反映事物的固有 ...
2026-01-04在CDA(Certified Data Analyst)数据分析师的工作链路中,数据读取是连接原始数据与后续分析的关键桥梁。如果说数据采集是“获 ...
2026-01-04尊敬的考生: 您好! 我们诚挚通知您,CDA Level III 考试大纲将于 2025 年 12 月 31 日实施重大更新,并正式启用,2026年3月考 ...
2025-12-31“字如其人”的传统认知,让不少“手残党”在需要签名的场景中倍感尴尬——商务签约时的签名歪歪扭扭,朋友聚会的签名墙不敢落笔 ...
2025-12-31在多元统计分析的因子分析中,“得分系数”是连接原始观测指标与潜在因子的关键纽带,其核心作用是将多个相关性较高的原始指标, ...
2025-12-31对CDA(Certified Data Analyst)数据分析师而言,高质量的数据是开展后续分析、挖掘业务价值的基础,而数据采集作为数据链路的 ...
2025-12-31在中介效应分析(或路径分析)中,间接效应是衡量“自变量通过中介变量影响因变量”这一间接路径强度与方向的核心指标。不同于直 ...
2025-12-30