Skip to content

Instantly share code, notes, and snippets.

@gcmurphy
Last active August 29, 2015 14:26
Show Gist options
  • Save gcmurphy/b1cb0eadf230716e5bb4 to your computer and use it in GitHub Desktop.
Save gcmurphy/b1cb0eadf230716e5bb4 to your computer and use it in GitHub Desktop.
#!/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