Last active
August 29, 2015 14:26
-
-
Save gcmurphy/b1cb0eadf230716e5bb4 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import paramiko | |
import itertools | |
import multiprocessing | |
to_csv = lambda x: ', '.join(x) | |
allowed = lambda x: x == 'publickey' | |
good = "✓" | |
bad = "ಠ_ಠ" | |
fail = "ಠಿ_ಠ" | |
def try_connection(hostname): | |
if not hostname: | |
return | |
try: | |
client = paramiko.client.SSHClient() | |
client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy()) | |
client.connect(hostname, look_for_keys=False, | |
username="root", password='secret', timeout=1.0) | |
print("{:<40} {} i have root".format(hostname, bad)) | |
except paramiko.ssh_exception.BadAuthenticationType as err: | |
if all([allowed(x) for x in err.allowed_types]): | |
print("{:<40} {}".format(hostname, good)) | |
else: | |
print("{:<40} {} {}".format(hostname, bad, to_csv(err.allowed_types))) | |
except paramiko.ssh_exception.AuthenticationException as err: | |
print("{:<40} {} password auth enabled".format(hostname, bad)) | |
except Exception as err: | |
print("{:<40} {} connection failed".format(hostname, fail)) | |
def main(args): | |
pool = multiprocessing.Pool() | |
for arg in args: | |
with open(arg) as input_file: | |
pool.map(try_connection, [h.strip() for h in input_file.read().split('\n')]) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment