Created
April 23, 2021 10:54
-
-
Save ndaidong/743d56bf44f6416bd8ffb32e890f1588 to your computer and use it in GitHub Desktop.
Check SSL certificate expiration with Python
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 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