zoukankan      html  css  js  c++  java
  • python | 实现控制多台机器的脚本

    这个控制多台机器的思路值得学习

    # -*- coding: utf-8 -*-
    import optparse
    import pxssh
    
    class Client:
        def __init__(self,host,password,username):
            self.host = host
            self.password = password
            self.username = username
            self.session = self.connect()
    
        def connect(self):
            try:
                s = pxssh.pxssh()
                s.login(self.host , self.username, self.password)
                return s
            except Exception , e:
                print e
                print '[-]error connecting'
    
        def send_command(self, cmd):
            self.session.sendline(cmd)
            self.session.prompt()
            return self.session
    
    
    def botnetCommand(command):
        for client in botNet:
            output = Client.send_command(command)
            print '[*] Output from'  + Client.host
            print '[+]' + output +'
    '
    
    def addClient(host,user,password):
        client = Client(host,user,password)
        botNet.append(client)
    
    botNet = []
    addClient('10.1.1.0','root','tooy')
    addClient('10.1.1.2','root1','tooy2')
    addClient('10.1.1.1','root3','tooy4')
    botnetCommand('uname -v')
    botnetCommand('cat /etc/issue')
  • 相关阅读:
    day60----日考
    css之单位
    如何装双系统win10下装Ubuntu
    css之Grid Layout详解
    css之position详解
    html+css的用户注册界面
    self-introduction
    ps常用操作
    前端基础之BOM和DOM
    emment语法
  • 原文地址:https://www.cnblogs.com/J0ng/p/13252157.html
Copyright © 2011-2022 走看看