通过python脚本实现
# coding: utf-8
# 查询域名证书到期情况
import re
import time
import subprocess
from datetime import datetime
from io import StringIO
import requests,json
def send_msg(data, phone='18358570770'):
webhook = "https://oapi.dingtalk.com/robot/send?access_token=174ae8946096e738dcc910c8cebb20f198ac1a8050c6d050268731a62a76a403"
header = {
"Content-Type": "application/json",
}
data = {
"msgtype": "text",
"text": {
"content": data
},
"at": {
"atMobiles": [
phone,
],
"isAtAll": False
}
}
r = requests.post(url=webhook, headers=header, data=json.dumps(data))
def main(domain):
f = StringIO()
comm = "curl -Ivs https://%s --connect-timeout 10"%domain
result = subprocess.getstatusoutput(comm)
f.write(result[1])
print(f.getvalue())
m = re.search('start date: (.*?)n.*?expire date: (.*?)n.*?common name: (.*?)n.*?issuer: CN=(.*?)n', f.getvalue(), re.S)
if m:
start_date = m.group(1)
expire_date = m.group(2)
common_name = m.group(3)
issuer = m.group(4)
# time 字符串转时间数组
if start_date:
start_date = start_date.replace("月",'')
if expire_date:
expire_date = expire_date.replace("月",'')
start_date = time.strptime(start_date, "%m %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, "%m %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(remaining)
msg="""
title:到期提醒
域名:{}
通用名:{}
开始时间:{}
到期时间:{}
剩余时间:{}
颁发机构:{}
""".format(domain,common_name,start_date_st,expire_date_st,remaining,issuer)
if remaining
服务器租用托管,机房租用托管,主机租用托管,https://www.e1idc.com