# 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) #获取证书到期时间
remain_days = notafter - datetime.now() # 用证书到期时间减去当前时间
print(remain_days.days) #获取剩余天数


if __name__ == '__main__':
with open('domains.txt', 'r') as urls:
for url in urls.read().splitlines():
get_expire_time(url)

重点:domains.txt文件中的网址格式为

www.baidu.com
www.google.com

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-12-18
  • 2021-10-01
  • 2022-12-23
  • 2022-02-03
  • 2021-07-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
相关资源
相似解决方案