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

 

上一篇:JSHint


下一篇:ESP8266退出上电透传模式