Created
March 15, 2017 20:16
-
-
Save kkleidal/2b37740e2b33bea770f48211dc75eed0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import base64 | |
def keyscan(host): | |
p = subprocess.Popen(['/bin/sh', '-c', '(ssh-keyscan %s | grep ssh-rsa) 2>/dev/null' % host], stdout=subprocess.PIPE) | |
config = p.stdout.read().decode('ascii').split(' ') | |
p.wait() | |
if p.returncode != 0: | |
raise Exception("Could not scan %s for SSH key." % host) | |
config[2] = paramiko.RSAKey(data=base64.b64decode(config[2])) | |
return config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment