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


Python paramiko.MissingHostKeyPolicy方法代碼示例

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


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

示例1: attempt

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

示例2: __init__

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import MissingHostKeyPolicy [as 別名]
def __init__(self, application):
		"""
		:param application: The application which is using this policy.
		:type application: :py:class:`.KingPhisherClientApplication`
		"""
		self.application = application
		self.logger = logging.getLogger('KingPhisher.Client.' + self.__class__.__name__)
		super(MissingHostKeyPolicy, self).__init__() 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:10,代碼來源:ssh_host_key.py

示例3: ssh

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import MissingHostKeyPolicy [as 別名]
def ssh(ctx, domain_name):
    """Get the public key for a SSH server.

    Example:

        $ lokey fetch ssh chat.shazow.net
    """

    class FetchKeyPolicy(paramiko.MissingHostKeyPolicy):
        def __init__(self):
            self.key = None

        def missing_host_key(self, client, hostname, key):
            self.key = key

    fetch_key_policy = FetchKeyPolicy()
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(fetch_key_policy)
    try:
        client.connect(domain_name, username='lokey', timeout=5)
        key = fetch_key_policy.key.public_numbers
        key = ErisPublic(e=key.e, n=key.n)
        print key.to('ssh')
    except Exception as e:
        msg = ('Got "{message}" when attempting '
               'to connect to {domain_name}').format(
            domain_name=domain_name,
            message=str(e))
        raise click.ClickException(msg) 
開發者ID:jpf,項目名稱:lokey,代碼行數:31,代碼來源:__init__.py

示例4: upload_binary_to_client

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import MissingHostKeyPolicy [as 別名]
def upload_binary_to_client(hostname, port, username, password, file_src_path, binary_path, id_file):
    try:
        t = paramiko.Transport((hostname, port))
        pkey = None
        if id_file:
            pkey = paramiko.RSAKey.from_private_key_file(id_file)
            t.connect(username=username, pkey=pkey)
        else:
            t.connect(username=username, password=password)
        sftp = paramiko.SFTPClient.from_transport(t)

        # upload binary
        sftp.put(file_src_path, binary_path)
        t.close()

        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
        client.connect(hostname, port, username, password, pkey)

    except paramiko.AuthenticationException as e:
        raise Exception("Authentification error: " + e[0])
    except Exception, e:
        try:
            t.close()
            client.close()
        except:
            pass
        raise Exception("Caught exception when uploading binary [" + binary_path + "]: " + str(e)) 
開發者ID:usharesoft,項目名稱:hammr,代碼行數:31,代碼來源:hammr_utils.py

示例5: jumper_status_flush

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import MissingHostKeyPolicy [as 別名]
def jumper_status_flush(obj):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(settings.SSH_TIMEOUT)
    try:
        s.connect((str(obj.connect_ip), int(obj.sshport)))
    except socket.timeout as e:
        obj._status = settings.STATUS_JUMPER_UNREACHABLE
        obj.save()
        return
    except ConnectionRefusedError as e:
        obj._status = settings.STATUS_JUMPER_UNREACHABLE
        obj.save()
        return
    except Exception as e:
        obj._status = settings.STATUS_JUMPER_UNREACHABLE
        obj.save()
        return
    try:
        if obj.group is None or obj.group.key is None:
            obj._status = settings.STATUS_JUMPER_NO_KEY
            obj.save()
            return
    except Exception as e:
        obj._status = settings.STATUS_JUMPER_NO_KEY
        obj.save()
        return

    # 創建臨時目錄
    TMP = settings.OPS_ROOT + '/' + str(time.time()) + '/'
    if not os.path.exists(TMP):
        os.makedirs(TMP)

    KEY = TMP + str(time.time()) + '.key'
    write_key(obj.group.key, KEY)

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy)
    try:
        ssh.connect(hostname=obj.connect_ip, port=obj.sshport, username='root', key_filename=KEY)
    except paramiko.AuthenticationException as e:
        obj._status = settings.STATUS_JUMPER_WRONG_KEY
        obj.save()
        return

    obj._status = settings.STATUS_JUMPER_CAN_BE_USE
    obj.save() 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:48,代碼來源:tasks.py


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