當前位置: 首頁>>代碼示例>>Python>>正文


Python paramiko.WarningPolicy方法代碼示例

本文整理匯總了Python中paramiko.WarningPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Python paramiko.WarningPolicy方法的具體用法?Python paramiko.WarningPolicy怎麽用?Python paramiko.WarningPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在paramiko的用法示例。


在下文中一共展示了paramiko.WarningPolicy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _try_passwordless_paramiko

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _try_passwordless_paramiko(server, keyfile):
    """Try passwordless login with paramiko."""
    if paramiko is None:
        msg = "Paramiko unavailable, "
        if sys.platform == 'win32':
            msg += "Paramiko is required for ssh tunneled connections on Windows."
        else:
            msg += "use OpenSSH."
        raise ImportError(msg)
    username, server, port = _split_server(server)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())
    try:
        client.connect(server, port, username=username, key_filename=keyfile,
               look_for_keys=True)
    except paramiko.AuthenticationException:
        return False
    else:
        client.close()
        return True 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:23,代碼來源:tunnel.py

示例2: _try_passwordless_paramiko

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _try_passwordless_paramiko(server, keyfile):
    """Try passwordless login with paramiko."""
    if paramiko is None:
        msg = "Paramiko unavaliable, "
        if sys.platform == 'win32':
            msg += "Paramiko is required for ssh tunneled connections on Windows."
        else:
            msg += "use OpenSSH."
        raise ImportError(msg)
    username, server, port = _split_server(server)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())
    try:
        client.connect(server, port, username=username, key_filename=keyfile,
               look_for_keys=True)
    except paramiko.AuthenticationException:
        return False
    else:
        client.close()
        return True 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:tunnel.py

示例3: ssh_into_device

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def ssh_into_device(lport, interactive, decryption_type, full_reversing):
	print "[+] SSH'ing into device"
	try:
		ssh_client.load_system_host_keys()
		ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy)
		ssh_client.connect('localhost', port=lport, username='root', password=root_password)
		if interactive:
			interactive_shell()
		else:
			decrypt_application(decryption_type, lport, full_reversing)
			
	except Exception as e:
		print "[-] SSH error: ", e
		cleanup()
		sys.exit()
	finally:
		cleanup() 
開發者ID:ivRodriguezCA,項目名稱:decrypt-ios-apps-script,代碼行數:19,代碼來源:ios_ssh.py

示例4: _try_passwordless_paramiko

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _try_passwordless_paramiko(server, keyfile):
    """Try passwordless login with paramiko."""
    if paramiko is None:
        msg = "Paramiko unavaliable, "
        if sys.platform == 'win32':
            msg += "Paramiko is required for ssh tunneled connections on Windows."
        else:
            msg += "use OpenSSH."
        raise ImportError(msg)
    username, server, port = _split_server(server)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    #client.set_missing_host_key_policy(paramiko.WarningPolicy())
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        client.connect(server, port, username=username, key_filename=keyfile,
               look_for_keys=True)
    except paramiko.AuthenticationException:
        return False
    else:
        client.close()
        return True 
開發者ID:korniichuk,項目名稱:rk,代碼行數:24,代碼來源:tunnel.py

示例5: _paramiko_tunnel

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
    """Function for actually starting a paramiko tunnel, to be passed
    to multiprocessing.Process(target=this), and not called directly.
    """
    username, server, port = _split_server(server)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())

    try:
        client.connect(server, port, username=username, key_filename=keyfile,
                       look_for_keys=True, password=password)
#    except paramiko.AuthenticationException:
#        if password is None:
#            password = getpass("%s@%s's password: "%(username, server))
#            client.connect(server, port, username=username, password=password)
#        else:
#            raise
    except Exception as e:
        print('*** Failed to connect to %s:%d: %r' % (server, port, e))
        sys.exit(1)

    # Don't let SIGINT kill the tunnel subprocess
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    try:
        forward_tunnel(lport, remoteip, rport, client.get_transport())
    except KeyboardInterrupt:
        print('SIGINT: Port forwarding stopped cleanly')
        sys.exit(0)
    except Exception as e:
        print("Port forwarding stopped uncleanly: %s"%e)
        sys.exit(255) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:35,代碼來源:tunnel.py

示例6: _paramiko_tunnel

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
    """Function for actually starting a paramiko tunnel, to be passed
    to multiprocessing.Process(target=this), and not called directly.
    """
    username, server, port = _split_server(server)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())

    try:
        client.connect(server, port, username=username, key_filename=keyfile,
                       look_for_keys=True, password=password)
#    except paramiko.AuthenticationException:
#        if password is None:
#            password = getpass("%s@%s's password: "%(username, server))
#            client.connect(server, port, username=username, password=password)
#        else:
#            raise
    except Exception as e:
        print('*** Failed to connect to %s:%d: %r' % (server, port, e))
        sys.exit(1)

    # print('Now forwarding port %d to %s:%d ...' % (lport, server, rport))

    try:
        forward_tunnel(lport, remoteip, rport, client.get_transport())
    except KeyboardInterrupt:
        print('SIGINT: Port forwarding stopped cleanly')
        sys.exit(0)
    except Exception as e:
        print("Port forwarding stopped uncleanly: %s"%e)
        sys.exit(255) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:34,代碼來源:tunnel.py

示例7: _paramiko_tunnel

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
    """Function for actually starting a paramiko tunnel, to be passed
    to multiprocessing.Process(target=this), and not called directly.
    """
    username, server, port = _split_server(server)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())

    try:
        client.connect(server, port, username=username, key_filename=keyfile,
                       look_for_keys=True, password=password)
#    except paramiko.AuthenticationException:
#        if password is None:
#            password = getpass("%s@%s's password: "%(username, server))
#            client.connect(server, port, username=username, password=password)
#        else:
#            raise
    except Exception as e:
        print ('*** Failed to connect to %s:%d: %r' % (server, port, e))
        sys.exit(1)
    
    # Don't let SIGINT kill the tunnel subprocess
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    
    try:
        forward_tunnel(lport, remoteip, rport, client.get_transport())
    except KeyboardInterrupt:
        print ('SIGINT: Port forwarding stopped cleanly')
        sys.exit(0)
    except Exception as e:
        print ("Port forwarding stopped uncleanly: %s"%e)
        sys.exit(255) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:35,代碼來源:tunnel.py

示例8: client

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def client(self):
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.WarningPolicy())
        cfg = {
            "hostname": self.host.name,
            "port": int(self.host.port) if self.host.port else 22,
            "username": self.host.user,
            "timeout": self.timeout,
        }
        if self.ssh_config:
            with open(self.ssh_config) as f:
                ssh_config = paramiko.SSHConfig()
                ssh_config.parse(f)
                self._load_ssh_config(client, cfg, ssh_config)
        else:
            # fallback reading ~/.ssh/config
            default_ssh_config = os.path.join(
                os.path.expanduser('~'), '.ssh', 'config')
            try:
                with open(default_ssh_config) as f:
                    ssh_config = paramiko.SSHConfig()
                    ssh_config.parse(f)
            except IOError:
                pass
            else:
                self._load_ssh_config(client, cfg, ssh_config)

        if self.ssh_identity_file:
            cfg["key_filename"] = self.ssh_identity_file
        client.connect(**cfg)
        return client 
開發者ID:philpep,項目名稱:testinfra,代碼行數:33,代碼來源:paramiko.py

示例9: _paramiko_tunnel

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
    """Function for actually starting a paramiko tunnel, to be passed
    to multiprocessing.Process(target=this), and not called directly.
    """
    username, server, port = _split_server(server)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    #client.set_missing_host_key_policy(paramiko.WarningPolicy())
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    try:
        client.connect(server, port, username=username, key_filename=keyfile,
                       look_for_keys=True, password=password)
#    except paramiko.AuthenticationException:
#        if password is None:
#            password = getpass("%s@%s's password: "%(username, server))
#            client.connect(server, port, username=username, password=password)
#        else:
#            raise
    except Exception as e:
        print('*** Failed to connect to %s:%d: %r' % (server, port, e))
        sys.exit(1)

    # Don't let SIGINT kill the tunnel subprocess
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    try:
        forward_tunnel(lport, remoteip, rport, client.get_transport())
    except KeyboardInterrupt:
        print('SIGINT: Port forwarding stopped cleanly')
        sys.exit(0)
    except Exception as e:
        print("Port forwarding stopped uncleanly: %s"%e)
        sys.exit(255) 
開發者ID:korniichuk,項目名稱:rk,代碼行數:36,代碼來源:tunnel.py

示例10: __connect

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def __connect(self):
        try:
            self.__ssh = paramiko.SSHClient()
            self.__ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
            self.__ssh.connect(self.__host, username=self.__user,
                password=self.__password, timeout=self.__timeout)
            LOG.info("Connected to %s", self.__host)
        except paramiko.AuthenticationException:
            LOG.error("Authentication failed when connecting to %s",
                      self.__host)
            raise exceptions.NotAuthorized
        except paramiko.SSHException:
            LOG.error("Could not connect to %s. Giving up", self.__host)
            raise 
開發者ID:openstack,項目名稱:tacker,代碼行數:16,代碼來源:cmd_executer.py

示例11: scp_upload

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def scp_upload(src_blob='Preproc.tar.gz', dst_blob="~", options={'hostname': 'lecun', 'username': 'shawley'}, progress=simple_callback):
    # from https://gist.github.com/acdha/6064215

    #--- Make the Paramiko SSH thing use my .ssh/config file (b/c I like ProxyCommand!)
    client = SSHClient()
    client.load_system_host_keys()
    client._policy = WarningPolicy()
    client.set_missing_host_key_policy(WarningPolicy())  # hmm. WarningPolicy? Most people use AutoAddPolicy. 

    ssh_config = SSHConfig()
    user_config_file = os.path.expanduser("~/.ssh/config")
    if os.path.exists(user_config_file):
        with open(user_config_file) as f:
            ssh_config.parse(f)

    cfg = {'hostname': options['hostname'], 'username': options["username"]}

    user_config = ssh_config.lookup(cfg['hostname'])
    for k in ('hostname', 'username', 'port'):
        if k in user_config:
            cfg[k] = user_config[k]

    if 'proxycommand' in user_config:
        cfg['sock'] = ProxyCommand(user_config['proxycommand'])

    client.connect(**cfg)

    socket_timeout = None # number of seconds for timeout. None = never timeout. TODO: None means program may hang. But timeouts are annoying!

    # SCPCLient takes a paramiko transport and progress callback as its arguments.
    scp = SCPClient(client.get_transport(), progress=progress, socket_timeout=socket_timeout)

    # NOW we can finally upload! (in a separate process)
    #scp.put(src_blob, dst_blob)   # now in scp_thread

    # we want this to be non-blocking so we stick it in a thread
    thread = threading.Thread(target=scp_thread, args=(scp,src_blob, dst_blob) )
    thread.start()

    #scp.close()  # now in scp_thread 
開發者ID:drscotthawley,項目名稱:panotti,代碼行數:42,代碼來源:scp_upload.py

示例12: _setup_ssh

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _setup_ssh(self,
                   hostname,
                   port, 
                   username = None,
                   password = None):
        self.ssh = paramiko.SSHClient()        
        # ssh_client.load_system_host_keys()        
        self.ssh.set_missing_host_key_policy(paramiko.WarningPolicy)
        self.ssh.connect(hostname, port=port, username=username, password=password)
        assert(self.ssh.get_transport().is_active())
        transport = self.ssh.get_transport()
        transport.set_keepalive(60) 
開發者ID:deepmodeling,項目名稱:dpgen,代碼行數:14,代碼來源:SSHContext.py

示例13: _setup_ssh

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def _setup_ssh(self,
                   hostname,
                   port, 
                   username = None,
                   password = None):
        ssh_client = paramiko.SSHClient()        
        ssh_client.load_system_host_keys()
        ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy)
        ssh_client.connect(hostname, port=port, username=username, password=password)
        assert(ssh_client.get_transport().is_active())
        return ssh_client 
開發者ID:deepmodeling,項目名稱:dpgen,代碼行數:13,代碼來源:RemoteJob.py

示例14: run

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def run():
    '''
    main
    '''
    passwords = []

    for password in open(PASSWORD).read().split('\n'):
        passwords.append(password)

    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy)

    for pwd in passwords:
        try:
            client.connect(TARGET, port=22,
                           username="root",
                           password=pwd,
                           look_for_keys=False,
                           timeout=10)

            _, stdout, stderr = client.exec_command(COMMAND)
            print("exec {}:".format(COMMAND))
            print(TARGET, stdout, stderr)
        except (paramiko.SSHException, paramiko.ssh_exception.NoValidConnectionsError):
            continue
    client.close() 
開發者ID:jm33-m0,項目名稱:mec,代碼行數:29,代碼來源:ssh_bruteforce.py

示例15: main

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import WarningPolicy [as 別名]
def main():
    options, server, remote = parse_options()
    
    password = None
    if options.readpass:
        password = getpass.getpass('Enter SSH password: ')
    
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())

    verbose('Connecting to ssh host %s:%d ...' % (server[0], server[1]))
    try:
        client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
                       look_for_keys=options.look_for_keys, password=password)
    except Exception as e:
        print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
        sys.exit(1)

    verbose('Now forwarding remote port %d to %s:%d ...' % (options.port, remote[0], remote[1]))

    try:
        reverse_forward_tunnel(options.port, remote[0], remote[1], client.get_transport())
    except KeyboardInterrupt:
        print('C-c: Port forwarding stopped.')
        sys.exit(0) 
開發者ID:hpe-storage,項目名稱:python-hpedockerplugin,代碼行數:28,代碼來源:rforward.py


注:本文中的paramiko.WarningPolicy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。