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


Python paramiko.AuthenticationException方法代碼示例

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


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

示例1: fetch_remote_crashes

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def fetch_remote_crashes(self):
        """
        some exception handling code is taken from https://www.programcreek.com/python/example/105570/scp.SCPClient
        """
        try:
            ssh = SSHClient()
            ssh.load_system_host_keys()
            ssh.connect(hostname=config.remote_system_ip)
            self.copy_crashes_dir_with_scp(ssh)
        except AuthenticationException:
            print("Authentication failed, please verify your credentials: %s")
        except SSHException as sshException:
            print("Unable to establish SSH connection: %s" % sshException)
        except BadHostKeyException as badHostKeyException:
            print("Unable to verify server's host key: %s" % badHostKeyException)
        finally:
            ssh.close() 
開發者ID:fkie-cad,項目名稱:LuckyCAT,代碼行數:19,代碼來源:RemoteCrashFetcher.py

示例2: connect

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [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

示例3: _try_passwordless_paramiko

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [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

示例4: _try_passwordless_paramiko

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [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

示例5: test_connectivity

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def test_connectivity(self, time_out=None):
        """ Tests if the SSH is active

            Arguments:
            - time_out: Timeout to connect.

            Returns: True if the connection is established or False otherwise

            Raises:
                Exception
        """
        try:
            client, proxy = self.connect(time_out)
            client.close()
            if proxy:
                proxy.close()
            return True
        except paramiko.AuthenticationException:
            raise AuthenticationException("Authentication Error!!")
        except paramiko.SSHException as e:
            if str(e) == "No authentication methods available":
                raise AuthenticationException("Authentication Error!!")
            return False
        except Exception:
            return False 
開發者ID:grycap,項目名稱:im,代碼行數:27,代碼來源:SSH.py

示例6: attempt

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def attempt(Password):

    IP = "127.0.0.1"
    USER = "rejah"
    PORT=22
      
    try:

        ssh = paramiko.SSHClient()
        ssh.load_system_host_keys()
        ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
 
        try:
            ssh.connect(IP , port=PORT, username=USER, password=Password)
            print "Connected successfully. Password = "+Password
        except paramiko.AuthenticationException, error:
            print "Incorrect password: "+Password
            pass
        except socket.error, error:
            print error
            pass 
開發者ID:PacktPublishing,項目名稱:Effective-Python-Penetration-Testing,代碼行數:23,代碼來源:ssh-brute-force-threded.py

示例7: execute

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def execute(self, command):
        """
        Executes command on remote hosts

        :type command: str
        :param command: command to be run on remote host
        """
        try:
            if self.ssh.get_transport() is not None:
                logger.debug('{0}: executing "{1}"'.format(self.target_address,
                                                           command))
                stdin, stdout, stderr = self.ssh.exec_command(command)
                return dict(zip(['stdin', 'stdout', 'stderr'],
                                [stdin, stdout, stderr]))
            else:
                raise SSHConnectionError(self.target_address,
                                         "ssh transport is closed")
        except (AuthenticationException, SSHException,
                ChannelException, SocketError) as ex:
            logger.critical(("{0} execution failed on {1} with exception:"
                             "{2}".format(command, self.target_address,
                                               ex)))
            raise SSHCommandError(self.target_address, command, ex) 
開發者ID:ThreatResponse,項目名稱:margaritashotgun,代碼行數:25,代碼來源:remote_shell.py

示例8: execute_async

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def execute_async(self, command, callback=None):
        """
        Executes command on remote hosts without blocking

        :type command: str
        :param command: command to be run on remote host
        :type callback: function
        :param callback: function to call when execution completes
        """
        try:
            logger.debug(('{0}: execute async "{1}"'
                          'with callback {2}'.format(self.target_address,
                                                     command,
                                                     callback)))
            future = self.executor.submit(self.execute, command)
            if callback is not None:
                future.add_done_callback(callback)
            return future
        except (AuthenticationException, SSHException,
                ChannelException, SocketError) as ex:
            logger.critical(("{0} execution failed on {1} with exception:"
                             "{2}".format(command, self.target_address,
                                               ex)))
            raise SSHCommandError(self.target_address, command, ex) 
開發者ID:ThreatResponse,項目名稱:margaritashotgun,代碼行數:26,代碼來源:remote_shell.py

示例9: ssh_connect

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def ssh_connect(self, args):
        ssh = self.ssh_client
        dst_addr = args[:2]
        logging.info('Connecting to {}:{}'.format(*dst_addr))

        try:
            ssh.connect(*args, timeout=options.timeout)
        except socket.error:
            raise ValueError('Unable to connect to {}:{}'.format(*dst_addr))
        except paramiko.BadAuthenticationType:
            raise ValueError('Bad authentication type.')
        except paramiko.AuthenticationException:
            raise ValueError('Authentication failed.')
        except paramiko.BadHostKeyException:
            raise ValueError('Bad host key.')

        term = self.get_argument('term', u'') or u'xterm'
        chan = ssh.invoke_shell(term=term)
        chan.setblocking(0)
        worker = Worker(self.loop, ssh, chan, dst_addr)
        worker.encoding = options.encoding if options.encoding else \
            self.get_default_encoding(ssh)
        return worker 
開發者ID:huashengdun,項目名稱:webssh,代碼行數:25,代碼來源:handler.py

示例10: _try_passwordless_paramiko

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [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

示例11: do_ssh

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def do_ssh(self, username):
		while not self.passwords.empty():
			time.sleep(0.1)
			password = self.passwords.get()
			ssh = paramiko.SSHClient()
			ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
			try:
				ssh.connect(self.host_ip, port=self.host_port, username=username, password=password, timeout=self.timeout)
				print info_out + ffb + "{} : {:.<50} {}".format(username, password, fgb + "Successful" + sf)
				ssh.close(); exit(0)
			except paramiko.AuthenticationException:
				print ver_out + ffb + "{} : {:.<50} {}".format(username, password, frb + "Failed" + sf)
			except socket.error, e:
				print err_out + ffb + "{} : {:.<50} {}".format(username, password, fcb + "Connection Failed" + sf)
			except paramiko.SSHException: 
				print err_out + ffb + "{} : {:.<50} {}".format(username, password, fbb + "Error" + sf) 
開發者ID:d3vilbug,項目名稱:Brutal_SSH,代碼行數:18,代碼來源:brutal_SSH.py

示例12: loginandrun

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def loginandrun(hostname,uname,pwd,command):
     try:
        log.info("Establishing ssh connection")
        client = getsshClient()
        client.load_system_host_keys()
        client.connect(hostname)#,username=uname)#,password=pwd)
     except paramiko.AuthenticationException:
        print("Authentication failed, please verify your credentials: %s")
     except paramiko.SSHException as sshException:
        print("Unable to establish SSH connection: %s" % sshException)
     except paramiko.BadHostKeyException as badHostKeyException:
        print("Unable to verify server's host key: %s" % badHostKeyException)
     try:
        stdin, stdout, stderr = client.exec_command(command)
        result = stderr.read()
        if len(result)  > 0:
            print("hit error" + result)

     except Exception as e:
        print("Operation error: %s", e)


# Any new implementation to use this method 
開發者ID:WiproOpenSource,項目名稱:galaxia,代碼行數:25,代碼來源:paramiko_helper.py

示例13: loginandcopydir

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def loginandcopydir(hostname,uname,pwd,sfile,tfile,recursive,preserve_times):
     try:
        log.info("Establishing ssh connection")
        client = getsshClient()
        client.load_system_host_keys()
        client.connect(hostname) #,username=uname)#,password=pwd)
     except paramiko.AuthenticationException:
        print("Authentication failed, please verify your credentials: %s")
     except paramiko.SSHException as sshException:
        print("Unable to establish SSH connection: %s" % sshException)
     except paramiko.BadHostKeyException as badHostKeyException:
        print("Unable to verify server's host key: %s" % badHostKeyException)
     except Exception as e:
        print(e.args)
     try:
        scpclient = scp.SCPClient(client.get_transport())
        scpclient.put(sfile,tfile,recursive,preserve_times)
     except scp.SCPException as e:
        print("Operation error: %s", e)

# Deprecated 
開發者ID:WiproOpenSource,項目名稱:galaxia,代碼行數:23,代碼來源:paramiko_helper.py

示例14: loginandcopy

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def loginandcopy(hostname,uname,pwd,sfile,tfile):
     try:
        log.info("Establishing ssh connection")
        client = getsshClient()
        client.load_system_host_keys()
        client.connect(hostname)#,username=uname)#,password=pwd)
     except paramiko.AuthenticationException:
        print("Authentication failed, please verify your credentials: %s")
     except paramiko.SSHException as sshException:
        print("Unable to establish SSH connection: %s" % sshException)
     except paramiko.BadHostKeyException as badHostKeyException:
        print("Unable to verify server's host key: %s" % badHostKeyException)
     except Exception as e:
        print(e.args)
     try:
        log.info("Getting SCP Client")
        scpclient = scp.SCPClient(client.get_transport())
        log.info(scpclient)
        log.info("Hostname: %s", hostname)
        log.info("source file: %s", sfile)
        log.info("target file: %s", tfile)
        scpclient.put(sfile,tfile)
     except scp.SCPException as e:
        print("Operation error: %s", e) 
開發者ID:WiproOpenSource,項目名稱:galaxia,代碼行數:26,代碼來源:paramiko_helper.py

示例15: check_sshBF

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import AuthenticationException [as 別名]
def check_sshBF(ip):
	print colores.HEADER + "[*][TARGET] SSH connect to " + ip + colores.normal
	paramiko.util.log_to_file("filename.log")
	fail = 0
	user="root"
	for p in passwords:
		ssh = paramiko.SSHClient()
		ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
		try:
			print colores.verde + "|----[INFO] Try user: root password: " + p + colores.normal
			ssh.connect(ip, username=user, password=p, timeout=10)
		except paramiko.AuthenticationException, error:
			print "|----[ERROR] incorrect password... root@" + ip + ":" + p
			continue
		except socket.error, error:
			fail += 1
			print error
			continue 
開發者ID:Quantika14,項目名稱:Shodita,代碼行數:20,代碼來源:gigante-ssh-bot.py


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