jcici
#! /usr/bin/python
# -*- coding:utf-8 -*-
# Author: panb

##此脚本用来获取https证书过期时间,需要先执行pip3 install pyopenssl
import argparse;
from urllib3.contrib import pyopenssl as reqs;
from datetime import datetime;

#命令行参数
parser = argparse.ArgumentParser(description=\'本脚本获取https证书到期时间\');
parser.add_argument(\'-w\', \'-www\', metavar=\'https网站,如www.jcici.com\',required=True, dest=\'sites\', nargs=\'+\', help=\'输入监控的https网站\')
args = parser.parse_args()

#公网验证
def get_notafter(www):
    cert = reqs.OpenSSL.crypto.load_certificate(reqs.OpenSSL.crypto.FILETYPE_PEM, reqs.ssl.get_server_certificate((www, 443)));

    notafter = datetime.strptime(cert.get_notAfter().decode()[0:-1], \'%Y%m%d%H%M%S\');
    remain_days = notafter - datetime.now();
    print(www, \'证书到期天数是:\', remain_days.days);

#输出结果
try:
    for site in args.sites:
        get_notafter(site);
except Exception as e:
    print("出现错误,请检查域名是否正确或者可达性");

 

分类:

技术点:

相关文章:

  • 2022-02-05
  • 2021-12-23
  • 2021-07-14
  • 2022-12-23
  • 2021-11-21
  • 2021-08-25
  • 2021-07-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-05-29
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案