Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import json
  2. import ssl, socket
  3.  
  4. with open('/tmp/domains.json') as f:
  5. data = json.load(f)
  6.  
  7. domains = []
  8.  
  9. for record in data['ResourceRecordSets']:
  10. if record['Type'] in ['A','CNAME']:
  11. try:
  12. domains.append({'name': record['Name'].rstrip('.'), 'value':record['ResourceRecords'][0]['Value']})
  13. except:
  14. pass
  15.  
  16. for domain in domains:
  17. ctx = ssl.create_default_context()
  18. s = ctx.wrap_socket(socket.socket(), server_hostname=domain['name'])
  19. s.settimeout(2)
  20. try:
  21. s.connect((domain['name'], 443))
  22. except:
  23. continue
  24. cert = s.getpeercert()
  25. subject = dict(x[0] for x in cert['subject'])
  26. issuer = dict(x[0] for x in cert['issuer'])
  27. issued_to = subject['commonName']
  28. issued_by = issuer['commonName']
  29. expiry_dt = cert['notAfter']
  30.  
  31. print(domain['name'], domain['value'], issued_to, issued_by, expiry_dt, sep=',')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement