Python3 查询证书到期时间+剩余天数
作者:互联网
# coding: utf-8
from urllib3.contrib import pyopenssl as reqs
from datetime import datetime
def get_expire_time(url):
cert = reqs.OpenSSL.crypto.load_certificate(reqs.OpenSSL.crypto.FILETYPE_PEM, reqs.ssl.get_server_certificate((url, 443)))
notafter = datetime.strptime(cert.get_notAfter().decode()[0:-1], '%Y%m%d%H%M%S') #获取到的时间戳格式是ans.1的,需要转换
print (notafter)
if __name__ == '__main__':
with open('domains.txt', 'r') as urls:
for url in urls.read().splitlines():
print(url)
get_expire_time(url)
重点:domains.txt文件中的网址格式为
www.baidu.com
www.google.com
标签:__,txt,get,url,天数,证书,reqs,notafter,Python3 来源: https://www.cnblogs.com/qiqi-yhq/p/12028373.html