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)
评论列表
文章目录