久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

基于python檢查SSL證書到期情況代碼實例

瀏覽:4日期:2022-07-31 08:40:56

結合郵件告警和頁面展示,再多的域名證書到期情況即可立馬知道

代碼示例:

# coding: utf-8 # 查詢域名證書到期情況import reimport timeimport subprocessfrom datetime import datetimefrom io import StringIOdef main(domain): f = StringIO() comm = f'curl -Ivs https://{domain} --connect-timeout 10' result = subprocess.getstatusoutput(comm) f.write(result[1]) m = re.search(’start date: (.*?)n.*?expire date: (.*?)n.*?common name: (.*?)n.*?issuer: CN=(.*?)n’, f.getvalue(), re.S) start_date = m.group(1) expire_date = m.group(2) common_name = m.group(3) issuer = m.group(4) # time 字符串轉時間數組 start_date = time.strptime(start_date, '%b %d %H:%M:%S %Y GMT') start_date_st = time.strftime('%Y-%m-%d %H:%M:%S', start_date) # datetime 字符串轉時間數組 expire_date = datetime.strptime(expire_date, '%b %d %H:%M:%S %Y GMT') expire_date_st = datetime.strftime(expire_date,'%Y-%m-%d %H:%M:%S') # 剩余天數 remaining = (expire_date-datetime.now()).days print (’域名:’, domain) print (’通用名:’, common_name) print (’開始時間:’, start_date_st) print (’到期時間:’, expire_date_st) print (f’剩余時間: {remaining}天’) print (’頒發機構:’, issuer) print (’*’*30) time.sleep(0.5)if __name__ == '__main__': domains = [’www.baidu.com’] for domain in domains: main(domain)

結果示例:

域名: www.baidu.com通用名: baidu.com開始時間: 2019-05-09 01:22:02到期時間: 2020-06-25 05:31:02剩余時間: 82天頒發機構: GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE******************************

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 横峰县| 灌南县| 宜宾县| 大田县| 苍梧县| 马尔康县| 太原市| 浪卡子县| 营山县| 肥城市| 甘德县| 伊川县| 太原市| 博兴县| 台山市| 黔西| 进贤县| 龙陵县| 乌拉特后旗| 绥阳县| 托克托县| 长治县| 芜湖市| 新建县| 连城县| 郑州市| 丰镇市| 大安市| 桦甸市| 尚义县| 屯门区| 沁源县| 楚雄市| 东明县| 本溪市| 吉首市| 佳木斯市| 通辽市| 垫江县| 盐山县| 平远县|