Hello I am trying to build a script that will list sites' SSL cert expiration date. The first function of the code def sslExpiresDate
works great on its own. It's when I add the second function def all_sites_list
where my code has broken. I don't know how to run sslExpiresDate
to get an outcome for each URL in the list sites
. I have tried to do this by building a second function and calling the first one from it, but it does not work.
I would like the expected outcome to be in a readable table format (but I haven't even gotten that far). Something like:
SITE EXP DATE
www.site1.com 03-05-18
www.site2.com 08-12-19
www.site3.com 12-12-21
Meanwhile here is the code I'm struggling with. Thanks:
import OpenSSL
import ssl
sites = ['www.site1.com', 'www.site2.com', 'www.site3.com']
def sslExpiresDate():
cert = ssl.get_server_certificate((sites, 443))
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
print(x509.get_notAfter())
return
def all_sites_list(sites, sslExpiresDate):
for site in sites():
sslExpiresDate(site)
return
all_sites_list(sites, sslExpiresDate)