Skip to content

Instantly share code, notes, and snippets.

@ndaidong
Created April 23, 2021 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndaidong/743d56bf44f6416bd8ffb32e890f1588 to your computer and use it in GitHub Desktop.
Save ndaidong/743d56bf44f6416bd8ffb32e890f1588 to your computer and use it in GitHub Desktop.
Check SSL certificate expiration with Python
#!/usr/bin/env python3
import ssl
import OpenSSL # pip install pyopenssl
from datetime import datetime
def get_cert_expiration(domain):
cert = ssl.get_server_certificate((domain, 443))
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
expiration = datetime.strptime(x509.get_notAfter().decode("utf-8"),"%Y%m%d%H%M%SZ")
return str(expiration)
def start():
domain_list = [
'google.com',
'twitter.com'
]
for domain in domain_list:
print(f'checking domain {domain}')
result = get_cert_expiration(domain)
print(result)
if __name__ == '__main__':
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment