Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import ssl, socket
- with open('/tmp/domains.json') as f:
- data = json.load(f)
- domains = []
- for record in data['ResourceRecordSets']:
- if record['Type'] in ['A','CNAME']:
- try:
- domains.append({'name': record['Name'].rstrip('.'), 'value':record['ResourceRecords'][0]['Value']})
- except:
- pass
- for domain in domains:
- ctx = ssl.create_default_context()
- s = ctx.wrap_socket(socket.socket(), server_hostname=domain['name'])
- s.settimeout(2)
- try:
- s.connect((domain['name'], 443))
- except:
- continue
- cert = s.getpeercert()
- subject = dict(x[0] for x in cert['subject'])
- issuer = dict(x[0] for x in cert['issuer'])
- issued_to = subject['commonName']
- issued_by = issuer['commonName']
- expiry_dt = cert['notAfter']
- print(domain['name'], domain['value'], issued_to, issued_by, expiry_dt, sep=',')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement