https://stackoverflow.com/questions/30862099/how-c...#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import ssl, socket
hostname = sys.argv[1:][0]
ctx = ssl.create_default_context()
s = ctx.wrap_socket(socket.socket(), server_hostname=hostname)
s.connect((hostname, 443))
cert = s.getpeercert()
subject = dict(x[0] for x in cert['subject'])
issuer = dict(x[0] for x in cert['issuer'])
print(subject)
print(issuer)
# python check_sert.py thawte.com
{'organizationalUnitName': u'Infrastructure Operations', 'organizationName': u'Thawte, Inc.', 'businessCategory': u'Private Organization', 'serialNumber': u'3898261', 'commonName': u'www.thawte.com', 'stateOrProvinceName': u'California', 'countryName': u'US', '1.3.6.1.4.1.311.60.2.1.2': u'Delaware', '1.3.6.1.4.1.311.60.2.1.3': u'US', 'localityName': u'Mountain View'}
{'countryName': u'US', 'commonName': u'thawte EV SSL CA - G3', 'organizationName': u'thawte, Inc.'}
# python check_sert.py toster.ru
{'organizationalUnitName': u'PositiveSSL', 'commonName': u'toster.ru'}
{'countryName': u'GB', 'commonName': u'COMODO RSA Domain Validation Secure Server CA', 'organizationName': u'COMODO CA Limited', 'localityName': u'Salford', 'stateOrProvinceName': u'Greater Manchester'}