Last active
September 10, 2017 11:05
-
-
Save Ikke/fb098706639a13c243f1399603f18ed7 to your computer and use it in GitHub Desktop.
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
#!/bin/env python3 | |
import sys | |
import os | |
import time | |
import datetime | |
from sh import openssl | |
from datetime import datetime as dt | |
if len(sys.argv) < 2: | |
print("Usage: ", sys.argv[0], " <domain>") | |
sys.exit(1) | |
domain = sys.argv[1] | |
if not domain: | |
print("Usage: ", sys.argv[0], " <domain>") | |
sys.exit(1) | |
cert = "" | |
found_cert = False | |
for line in openssl.s_client(*"-connect {0}:443 -servername {0}".format(domain).split(" "), _in=os.devnull): | |
if "-----END CERTIFICATE-----" in line: | |
cert += line | |
break | |
elif "-----BEGIN CERTIFICATE-----" in line: | |
found_cert = True | |
cert += line | |
elif found_cert == True: | |
cert += line | |
if found_cert == False or cert.strip() == "": | |
print(0) | |
sys.exit(0) | |
end_date = openssl.x509(*"-noout -enddate".split(" "), _in=cert).strip().split("=")[1] | |
# Mar 20 20:44:00 2016 GMT | |
delta = dt.strptime(end_date, "%b %d %H:%M:%S %Y %Z") - dt.utcnow() | |
print(delta.days) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment