Created
April 8, 2014 01:17
-
-
Save coderanger/10080125 to your computer and use it in GitHub Desktop.
Quick script to scrape OpenSSL versions
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 | |
import os | |
import subprocess | |
import json | |
from boto.ec2 import connect_to_region | |
REGIONS = ['us-east-1', 'us-west-1', 'us-west-2'] | |
servers = [] | |
for region in REGIONS: | |
conn = connect_to_region(region, aws_access_key_id=os.environ['WS_ACCESS_KEY_ID'], aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY']) | |
for reservation in conn.get_all_instances(): | |
for instance in reservation.instances: | |
if instance.state != 'running': | |
continue | |
data = dict((k,v) for k,v in instance.__dict__.iteritems() if isinstance(k, basestring) and isinstance(v, basestring)) | |
servers.append(data) | |
try: | |
for s in servers: | |
if s.get('vpc_id'): | |
s['real_ip_address'] = s['private_ip_address'] | |
else: | |
s['real_ip_address'] = s['ip_address'] | |
print 'Trying to contact {}'.format(s['real_ip_address']) | |
try: | |
cmd = "ssh -o ConnectTimeout=5 -o StrictHostkeyChecking=no -o UserKnownHostsFile=/dev/null {} openssl version".format(s['real_ip_address']).split() | |
s['openssl_raw_version'] = subprocess.check_output(cmd) | |
print s['openssl_raw_version'] | |
except subprocess.CalledProcessError as e: | |
print 'Unable to contact {}'.format(s['real_ip_address']) | |
s['openssl_raw_version'] = None | |
s['openssl_error'] = str(e) | |
finally: | |
json.dump(servers, open('recon.json', 'wb')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typo on Line 14, WS == AWS?