当前位置: 首页>>代码示例>>Python>>正文


Python paramiko.AutoAddPolicy方法代码示例

本文整理汇总了Python中paramiko.AutoAddPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python paramiko.AutoAddPolicy方法的具体用法?Python paramiko.AutoAddPolicy怎么用?Python paramiko.AutoAddPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在paramiko的用法示例。


在下文中一共展示了paramiko.AutoAddPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ssh_edit_file

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def ssh_edit_file(adress, user, passw, remotefile, regex, replace):
        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        trans = paramiko.Transport((adress, 22))
        trans.connect(username=user, password=passw)
        sftp = paramiko.SFTPClient.from_transport(trans)
        f_in = sftp.file(remotefile, "r")
        c_in = f_in.read()
        pattern = re.compile(regex, re.MULTILINE | re.DOTALL)
        c_out = pattern.sub(replace, c_in)
        f_out = sftp.file(remotefile, "w")
        f_out.write(c_out)
        f_in.close()
        f_out.close()
        sftp.close()
        trans.close() 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:19,代码来源:ssh.py

示例2: _ssh_run_remote_command

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def _ssh_run_remote_command(self, cmd):
        ssh_client = paramiko.SSHClient()
        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh_client.connect(hostname=self.host,
                           username=self.config['ssh_user'],
                           password=self.config['ssh_password'])
        stdin, stdout, stderr = ssh_client.exec_command(cmd)

        out = stdout.read().decode().strip()
        error = stderr.read().decode().strip()
        if self.log_level:
            logger.info(out)
        if error:
            raise Exception('There was an error pulling the runtime: {}'.format(error))
        ssh_client.close()

        return out 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:19,代码来源:docker.py

示例3: connect

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def connect(self):
        """Call to set connection with remote client."""

        try:
            self.paramiko_session = paramiko.SSHClient()
            self.paramiko_session.set_missing_host_key_policy(
                paramiko.AutoAddPolicy())

            self.paramiko_session.connect(
                self.client.ip, username=self.client.user,
                password=self.client.pass_, key_filename=self.client.key,
                allow_agent=True, compress=self.client.compress)

        except (paramiko.AuthenticationException,
                paramiko.ssh_exception.NoValidConnectionsError) as e:
            self.logger.error(e)
            sys.exit(colored("> {}".format(e), 'red'))

        except paramiko.SSHException as e:
            self.logger.error(e)
            sys.exit(colored("> {}".format(e), 'red'))

        self.transfer = network.Network(
            self.paramiko_session, self.client.ip, self.client.port)
        self.transfer.open() 
开发者ID:kd8bny,项目名称:LiMEaide,代码行数:27,代码来源:network.py

示例4: run

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def run(self):
        print("Start try ssh => %s" % self.ip)
        username = "root"
        try:
            password = open(self.dict).read().split('\n')
        except:
            print("Open dict file `%s` error" % self.dict)
            exit(1)
        for pwd in password:
            try:
                ssh = paramiko.SSHClient()
                ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                ssh.connect(self.ip, self.port, username, pwd, timeout = self.timeout)
                print("\nIP => %s, Login %s => %s \n" % (self.ip, username, pwd))
                open(self.LogFile, "a").write("[ %s ] IP => %s, port => %d, %s => %s \n" % (time.asctime( time.localtime(time.time()) ), self.ip, self.port, username, pwd))
                break
            except:
                print("IP => %s, Error %s => %s" % (self.ip, username, pwd))
                pass 
开发者ID:euphrat1ca,项目名称:fuzzdb-collect,代码行数:21,代码来源:python多线程ssh爆破.py

示例5: sshInstall

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def sshInstall(retry,hostname):
    global user
    global password
    global userInsightfinder
    global licenseKey
    global samplingInterval
    global reportingInterval
    global agentType
    if retry == 0:
        print "Install Fail in", hostname
        q.task_done()
        return
    print "Start installing agent in", hostname, "..."
    try:
        s = paramiko.SSHClient()
        s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        if os.path.isfile(password) == True:
            s.connect(hostname, username=user, key_filename = password, timeout=60)
        else:
            s.connect(hostname, username=user, password = password, timeout=60)
        transport = s.get_transport()
        session = transport.open_session()
        session.set_combine_stderr(True)
        session.get_pty()
        session.exec_command("sudo rm -rf insightagent* InsightAgent* \n \
        wget --no-check-certificate https://github.com/insightfinder/InsightAgent/archive/master.tar.gz -O insightagent.tar.gz && \
        tar xzvf insightagent.tar.gz && \
        cd InsightAgent-master && deployment/checkpackages.sh -env\n")
        stdin = session.makefile('wb', -1)
        stdout = session.makefile('rb', -1)
        stdin.write(password+'\n')
        stdin.flush()
        session.recv_exit_status() #wait for exec_command to finish
        s.close()
        print "Install Succeed in", hostname
        q.task_done()
        return
    except paramiko.SSHException, e:
        print "Invalid Username/Password for %s:"%hostname , e
        return sshInstall(retry-1,hostname) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:42,代码来源:installInsightAgent.py

示例6: sshStopCron

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def sshStopCron(retry,hostname):
    global user
    global password
    if retry == 0:
        print "Stop Cron Failed in", hostname
        q.task_done()
        return
    try:
        s = paramiko.SSHClient()
        s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        if os.path.isfile(password) == True:
            s.connect(hostname, username=user, key_filename = password, timeout=60)
        else:
            s.connect(hostname, username=user, password = password, timeout=60)
        transport = s.get_transport()
        session = transport.open_session()
        session.set_combine_stderr(True)
        session.get_pty()
        command = "sudo mv /etc/cron.d/ifagent InsightAgent-master/ifagent."+time.strftime("%Y%m%d%H%M%S")+"\n"
        session.exec_command(command)
        stdin = session.makefile('wb', -1)
        stdout = session.makefile('rb', -1)
        stdin.write(password+'\n')
        stdin.flush()
        session.recv_exit_status() #wait for exec_command to finish
        s.close()
        print "Stopped Cron in ", hostname
        q.task_done()
        return
    except paramiko.SSHException, e:
        print "Invalid Username/Password for %s:"%hostname , e
        return sshStopCron(retry-1,hostname) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:34,代码来源:stopcron.py

示例7: sshStopCron

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def sshStopCron(retry,hostname):
    global user
    global password
    if retry == 0:
        print "Stop Cron Failed in", hostname
        q.task_done()
        return
    try:
        s = paramiko.SSHClient()
        s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        if os.path.isfile(password) == True:
            s.connect(hostname, username=user, key_filename = password, timeout=60)
        else:
            s.connect(hostname, username=user, password = password, timeout=60)
        transport = s.get_transport()
        session = transport.open_session()
        session.set_combine_stderr(True)
        session.get_pty()
        command = "./InsightAgent-master/hypervisor/stopcron.sh -t hypervisor\n"
        session.exec_command(command)
        stdin = session.makefile('wb', -1)
        stdout = session.makefile('rb', -1)
        stdin.write(password+'\n')
        stdin.flush()
        session.recv_exit_status() #wait for exec_command to finish
        s.close()
        print "Stopped Cron in ", hostname
        q.task_done()
        return
    except paramiko.SSHException, e:
        print "Invalid Username/Password for %s:"%hostname , e
        return sshStopCron(retry-1,hostname) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:34,代码来源:stopcron.py

示例8: execute_command_readlines

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def execute_command_readlines(address, usr, pwd, command):
        try:
            logger.debug("ssh " + usr + "@" + address + ", running : " +
                         command)
            client = paramiko.SSHClient()
            client.load_system_host_keys()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

            client.connect(address, username=usr, password=pwd)
            _, ss_stdout, ss_stderr = client.exec_command(command)
            r_out, r_err = ss_stdout.readlines(), ss_stderr.read()
            logger.debug(r_err)
            if len(r_err) > 5:
                logger.error(r_err)
            else:
                logger.debug(r_out)
            client.close()
        except IOError:
            logger.warning(".. host " + address + " is not up")
            return "host not up", "host not up"

        return r_out, r_err 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:24,代码来源:ssh.py

示例9: establish_connection

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def establish_connection(ip, username='', password=''):
    '''
    Use Paramiko to establish an SSH channel to the device

    Must return both return_conn_pre and return_conn so that the SSH
    connection is not garbage collected

    '''

    remote_conn_pre = paramiko.SSHClient()
    remote_conn_pre.set_missing_host_key_policy(
        paramiko.AutoAddPolicy())

    remote_conn_pre.connect(ip, username=username, password=password,
                            look_for_keys=False, allow_agent=False)

    remote_conn = remote_conn_pre.invoke_shell()

    # Clear banner and prompt
    output = remote_conn.recv(65535)

    return (remote_conn_pre, remote_conn, output) 
开发者ID:ktbyers,项目名称:pynet,代码行数:24,代码来源:ssh_connection.py

示例10: _connect

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def _connect(self) -> Tuple[paramiko.sftp_client.SFTPClient, paramiko.SSHClient]:
        """
        Connect via paramiko, and open a SSH session as well as a SFTP session.

        Returns:
            Tuple[paramiko.sftp_client.SFTPClient, paramiko.SSHClient]:
                - An SFTP client used to perform remote file operations. 
                - A high-level representation of a session with an SSH server.
        """
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.load_system_host_keys(filename=self.key)
        try:
            # If the server accepts the connection but the SSH daemon doesn't respond in 
            # 15 seconds (default in paramiko) due to network congestion, faulty switches, 
            # etc..., common solution is to enlarging the timeout variable.
            ssh.connect(hostname=self.address, username=self.un, banner_timeout=200)
        except:
            # This sometimes gives "SSHException: Error reading SSH protocol banner[Error 104] Connection reset by peer"
            # Try again:
            ssh.connect(hostname=self.address, username=self.un, banner_timeout=200)
        sftp = ssh.open_sftp()
        return sftp, ssh 
开发者ID:ReactionMechanismGenerator,项目名称:ARC,代码行数:25,代码来源:ssh.py

示例11: sshlogin

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def sshlogin(self, ip, port, user, keyfile, timeout):
        try:
            ssh = paramiko.SSHClient()
            paramiko.util.log_to_file("/dev/null")
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        except:
            pass
        else:
            brute = "LOG-SSH: " + ip + ":" + str(port) + " - " + user + ":" + keyfile + ":" + str(timeout)
            self.logger.log_file(brute)

            try:
                ssh.connect(ip, port, username=user, password=None, pkey=None, key_filename=keyfile, timeout=timeout,
                            allow_agent=False, look_for_keys=False)
                result = bcolors.OKGREEN + "SSH-SUCCESS: " + bcolors.ENDC + bcolors.OKBLUE + ip + ":" + str(
                    port) + " - " + user + ":" + keyfile + bcolors.ENDC
                self.logger.output_file(result)
                Main.is_success = 1
            except:
                pass 
开发者ID:galkan,项目名称:crowbar,代码行数:22,代码来源:main.py

示例12: taillog

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def taillog(request, hostname, port, username, password, private, tail):
    """
    执行 tail log 接口
    """
    channel_layer = get_channel_layer()
    user = request.user.username
    os.environ["".format(user)] = "true"
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    if password:
        ssh.connect(hostname=hostname, port=port, username=username, password=decrypt_p(password))
    else:
        pkey = paramiko.RSAKey.from_private_key_file("{0}".format(private))
        ssh.connect(hostname=hostname, port=port, username=username, pkey=pkey)
    cmd = "tail " + tail
    stdin, stdout, stderr = ssh.exec_command(cmd, get_pty=True)
    for line in iter(stdout.readline, ""):
        if os.environ.get("".format(user)) == 'false':
            break
        result = {"status": 0, 'data': line}
        result_all = json.dumps(result)
        async_to_sync(channel_layer.group_send)(user, {"type": "user.message", 'text': result_all}) 
开发者ID:hequan2017,项目名称:chain,代码行数:24,代码来源:views.py

示例13: connect

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def connect(hostname, port=22, username=None, password=None, pkey=None, timeout=None):
    import paramiko

    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    if pkey:
        ssh_key = paramiko.RSAKey.from_private_key(file_obj=io.StringIO(pkey))
    else:
        ssh_key = None

    timeout = timeout or 20
    logging.debug("Connecting to %s@%s:%d, timeout=%d", username, hostname, port, timeout)
    try:
        client.connect(hostname, port=port, username=username, password=password, pkey=ssh_key, timeout=timeout)
    except socket.timeout:
        raise AztkError("Connection timed out to: {}".format(hostname))

    return client 
开发者ID:Azure,项目名称:aztk,代码行数:21,代码来源:ssh.py

示例14: main

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def main():
    target_ip = etss_range(ip)
    print target_ip
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    for i in target_ip:
        try:
            ssh.connect(i, username=user, password=passwd)
            print "SSH connection established to %s" % (i)
            remote = ssh.invoke_shell()
            print "Interactive SSH session established"
            output = remote.recv(1000)
            print output
            #Disable pausing between screens of output
            screen_disable(remote)
            #Send commands to network device
            remote.send('\n')
            remote.send(cmd)
            time.sleep(2)
            output = remote.recv(5000)
            print output
        except:
            ssh.close()
            print "Problem connecting with ip: %s" % (i)
            continue 
开发者ID:networkingdvi,项目名称:HPN-Scripting,代码行数:27,代码来源:etss_ssh_in.py

示例15: weak_pass

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import AutoAddPolicy [as 别名]
def weak_pass(password, ip, port=22, timeout=5):
    for name in username_list:
        try:
            client = paramiko.SSHClient()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            client.connect(ip, port, str(name), str(password), timeout=timeout)
            found_password.append((ip, password))
            logger.warning('[True ] %s %s:%s' % (ip, name, password))
            append_2_file('[True ] %s %s:%s' % (ip, name, password))
            try:
                reverse_shell_cmd(client)
                alter_password_cmd(client, password)
                logger.warning('修改密码成功 %s %s:%s' % (ip, name, new_password))
                append_2_file('修改密码成功 %s %s:%s' % (ip, name, new_password))
                new_password_success.append((ip, new_password))
            except Exception as ex:
                logger.info(ex)
                logger.warning('修改密码失败 %s %s' % (ip, name))
            return True
        except Exception as e:
            logger.info(e)
            logger.debug('[False] %s %s:%s' % (ip, name, new_password))

    return False 
开发者ID:restran,项目名称:hacker-scripts,代码行数:26,代码来源:ssh_with_cmd.py


注:本文中的paramiko.AutoAddPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。