python脚本监听域名证书过期时间,并将通知消息到钉钉
版本一:
执行脚本带上 --dingtalk-webhook和–domains后指定钉钉token和域名
python3 ssl_spirtime.py --dingtalk-webhook https://oapi.dingtalk.com/robot/send?access_token=avd345324 --domains www.abc1.com www.abc2.com www.abc3.com
脚本如下
#!/usr/bin/python3
import ssl
import socket
from datetime import datetime
import argparse
import requestsdef get_ssl_cert_expiration(domain, port=443):context = ssl.create_default_context()conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)conn.connect((domain, port))cert = conn.getpeercert()conn.close()# Extract the expiration date from the certificatenot_after = cert['notAfter']# Convert the date string to a datetime objectexpiration_date = datetime.strptime(not_after, '%b %d %H:%M:%S %Y %Z')return expiration_datedef send_dingtalk_message(webhook_url, message):headers = {'Content-Type': 'application/json'}payload = {"msgtype": "text","text": {"content": message}}response = requests.post(webhook_url, json=payload, headers=headers)if response.status_code == 200:print("Message sent successfully to DingTalk")else:print(f"Failed to send message to DingTalk. HTTP Status Code: {response.status_code}")if __name__ == "__main__":parser = argparse.ArgumentParser(description="Test SSL certificate expiration for multiple domains")parser.add_argument("--dingtalk-webhook", required=True, help="DingTalk webhook URL")parser.add_argument("--domains", nargs='+', required=True, help="List of domains to test SSL certificate expiration")args = parser.parse_args()for domain in args.domains:expiration_date = get_ssl_cert_expiration(domain)current_date = datetime.now()days_remaining = (expiration_date - current_date).daysprint(f"SSL certificate for {domain} expires on {expiration_date}")print(f"Days remaining: {days_remaining} days")if days_remaining < 300:message = f"SSL certificate for {domain} will expire on {expiration_date}. Only {days_remaining} days remaining."send_dingtalk_message(args.dingtalk_webhook, message)
版本二
执行脚本带上 --dingtalk-webhook、–secret和–domains后指定钉钉token、密钥和域名
python3 ssl_spirtime4.py --dingtalk-webhook https://oapi.dingtalk.com/robot/send?access_token=abdcsardaef--secret SEC75bcc2abdfd --domains www.abc1.com www.abc2.com www.abc3.com
#!/usr/bin/python3
import ssl
import socket
from datetime import datetime
import argparse
import requests
import hashlib
import hmac
import base64
import timedef get_ssl_cert_expiration(domain, port=443):context = ssl.create_default_context()conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)conn.connect((domain, port))cert = conn.getpeercert()conn.close()# Extract the expiration date from the certificatenot_after = cert['notAfter']# Convert the date string to a datetime objectexpiration_date = datetime.strptime(not_after, '%b %d %H:%M:%S %Y %Z')return expiration_datedef send_dingtalk_message(webhook_url, secret, message):headers = {'Content-Type': 'application/json'}# Get the current timestamp in millisecondstimestamp = str(int(round(time.time() * 1000)))# Combine timestamp and secret to create a sign stringsign_string = f"{timestamp}\n{secret}"# Calculate the HMAC-SHA256 signaturesign = base64.b64encode(hmac.new(secret.encode(), sign_string.encode(), hashlib.sha256).digest()).decode()# Create the payload with the calculated signaturepayload = {"msgtype": "text","text": {"content": message},"timestamp": timestamp,"sign": sign}response = requests.post(f"{webhook_url}×tamp={timestamp}&sign={sign}", json=payload, headers=headers)if response.status_code == 200:print("Message sent successfully to DingTalk")else:print(f"Failed to send message to DingTalk. HTTP Status Code: {response.status_code}")if __name__ == "__main__":parser = argparse.ArgumentParser(description="Test SSL certificate expiration for multiple domains")parser.add_argument("--dingtalk-webhook", required=True, help="DingTalk webhook URL")parser.add_argument("--secret", required=True, help="DingTalk robot secret")parser.add_argument("--domains", nargs='+', required=True, help="List of domains to test SSL certificate expiration")args = parser.parse_args()for domain in args.domains:expiration_date = get_ssl_cert_expiration(domain)current_date = datetime.now()days_remaining = (expiration_date - current_date).daysprint(f"SSL certificate for {domain} expires on {expiration_date}")print(f"Days remaining: {days_remaining} days")if days_remaining < 10:message = f"SSL certificate for {domain} will expire on {expiration_date}. Only {days_remaining} days remaining."send_dingtalk_message(args.dingtalk_webhook, args.secret, message)
终极版本
python执行脚本时指定配置文件

python3 ssl_spirtime.py --config-file config.json
config.json配置文件内容如下
{"dingtalk-webhook": "https://oapi.dingtalk.com/robot/send?access_token=avbdcse345dd","secret": "SECaegdDEdaDSEGFdadd12334","domains": ["www.a.tel","www.b.com","www.c.app","www.d-cn.com","www.e.com","www.f.com","www.g.com","www.gg.com","www.sd.com","www.234.com","www.456.com","www.addf.com","www.advdwd.com","aqjs.aefdsdf.com","apap.adedgdg.com","cbap.asfew.com","ksjsw.adfewfd.cn","wdxl.aeffadaf.com","wspr.afefd.shop","sktprd.daeafsdf.shop","webskt.afaefafa.shop","www.afaead.cn","www.afewfsegs.co","www.aaeafsf.com","bdvt.aeraf.info","dl.afawef.co","dl.aefarge.com"]
}
脚本内容如下
#!/usr/bin/python3
import ssl
import socket
from datetime import datetime
import argparse
import requests
import hashlib
import hmac
import base64
import time
import jsondef get_ssl_cert_expiration(domain, port=443):context = ssl.create_default_context()conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)conn.connect((domain, port))cert = conn.getpeercert()conn.close()# Extract the expiration date from the certificatenot_after = cert['notAfter']# Convert the date string to a datetime objectexpiration_date = datetime.strptime(not_after, '%b %d %H:%M:%S %Y %Z')return expiration_datedef send_dingtalk_message(webhook_url, secret, message):headers = {'Content-Type': 'application/json'}# Get the current timestamp in millisecondstimestamp = str(int(round(time.time() * 1000)))# Combine timestamp and secret to create a sign stringsign_string = f"{timestamp}\n{secret}"# Calculate the HMAC-SHA256 signaturesign = base64.b64encode(hmac.new(secret.encode(), sign_string.encode(), hashlib.sha256).digest()).decode()# Create the payload with the calculated signaturepayload = {"msgtype": "text","text": {"content": message},"timestamp": timestamp,"sign": sign}response = requests.post(f"{webhook_url}×tamp={timestamp}&sign={sign}", json=payload, headers=headers)if response.status_code == 200:print("Message sent successfully to DingTalk")else:print(f"Failed to send message to DingTalk. HTTP Status Code: {response.status_code}")if __name__ == "__main__":# 从配置文件中加载配置with open("config.json", 'r') as config_file:config = json.load(config_file)dingtalk_webhook = config.get("dingtalk-webhook")secret = config.get("secret")domains = config.get("domains")for domain in domains:expiration_date = get_ssl_cert_expiration(domain)current_date = datetime.now()days_remaining = (expiration_date - current_date).daysprint(f"SSL certificate for {domain} expires on {expiration_date}")print(f"Days remaining: {days_remaining} days")if days_remaining < 10:message = f"SSL certificate for {domain} will expire on {expiration_date}. Only {days_remaining} days remaining."send_dingtalk_message(dingtalk_webhook, secret, message)
执行结果
/usr/bin/python3 /root/ssl_spirtime.py --config-file /root/config.json
SSL certificate for www.a.tel expires on 2024-06-08 23:59:59
Days remaining: 220 days
SSL certificate for www.b.com expires on 2024-05-23 07:45:13
Days remaining: 203 days
SSL certificate for www.c.app expires on 2024-05-23 07:45:13
Days remaining: 203 days
SSL certificate for www.d-cn.com expires on 2024-03-03 00:00:00
Days remaining: 122 days
SSL certificate for www.aed.com expires on 2024-11-17 06:30:15
Days remaining: 381 days
SSL certificate for www.afedf.com expires on 2024-06-20 23:59:59
Days remaining: 232 days
SSL certificate for www.aefdfd.com expires on 2024-06-20 23:59:59
钉钉告警消息如下

相关文章:
python脚本监听域名证书过期时间,并将通知消息到钉钉
版本一: 执行脚本带上 --dingtalk-webhook和–domains后指定钉钉token和域名 python3 ssl_spirtime.py --dingtalk-webhook https://oapi.dingtalk.com/robot/send?access_tokenavd345324 --domains www.abc1.com www.abc2.com www.abc3.com脚本如下 #!/usr/bin…...
那些看起来高大上的封装函数
什么 ToGray 只支持3通道图像, 让我看看怎么个事 就这么生硬的加了个判断 好家伙 调用了下opencv ,通道数都不判断一下...
go语言 | grpc原理介绍(三)
了解 gRPC 通信模式中的消息流 gRPC 支持四种通信模式,分别是简单 RPC、服务端流式 RPC、客户端流式 RPC 和双向流式 RPC。 简单 RPC 在gRPC中,一个简单的RPC调用遵循请求-响应模型,通常涉及以下几个关键步骤和组件: 请求头&a…...
记一次heapdump泄漏获取服务器权限
文章目录 一、漏洞原因二、漏洞利用三、漏洞进一步利用1、工具下载2、通过关键字查询3、通过配置redis的默认账号和密码进行登录4、添加定时计划任务,进行反弹shell5、成功获取服务器的shell补充四、总结五、免责声明一、漏洞原因 扫描目录发现某个spring框架存在大量泄露信息…...
大疆Livox MID-360安装ROS1/2驱动 Ubuntu20.04
文章目录 一、接线连接二、安装上位机可视化工具三、安装ROS驱动3.1 配置静态IP3.2 安装Livox SDK23.3 安装ROS驱动3.4 驱动 本文介绍如何在Ubuntu20.04中安装大疆Livox MID-360的ROS1/2驱动 一、接线连接 livox航插一分三线,其中航空母头连接激光雷达,…...
Android 重启App
要重启 Android 应用程序,可以使用 PendingIntent 和 AlarmManager 来实现。下面是一种实现方式: fun restartApp(context: Context) {val packageManager context.packageManagerval intent packageManager.getLaunchIntentForPackage(context.packa…...
C语言的前置知识:数据量单位、汇编语言和寄存器
数据量单位 位(bit)是计算机中最小的存储单位,每一位可以存储一个二进制码值的0或1。而字节(byte)则通常是由八个位组成的一个存储单元。在计算机中,字节是最小的可寻址单位,这意味着 CPU 在使…...
【IDEA】在工具栏设置快速创建包和类的图表
页面效果: 操作步骤: 设置 --> 外观与行为 --> 菜单与工具栏 --> 点击 主工具栏 --> 点击 ---- --> 点击 号 --> 添加操作 主菜单 --> 文件 --> 文件打开操作 --> 打开项目操作 --> 新建 --> 往下找 找到 clas…...
int arrayL = sizeof(array) / sizeof(array[0]);
我有一个四个元素的doublearray,这里我会得到4还是5? 在C或C中,使用 sizeof(array) / sizeof(array[0]) 来计算数组的长度是一种常见的方法。但是,这种方法只适用于在同一作用域中声明的数组,而不适用于函数参数传递的…...
FFmpeg——使用Canvas录制视频尚存问题的解决方案
个人简介 👀个人主页: 前端杂货铺 🙋♂️学习方向: 主攻前端方向,正逐渐往全干发展 📃个人状态: 研发工程师,现效力于中国工业软件事业 🚀人生格言: 积跬步…...
css进阶知识点速览
0前言 零基础部分的博客 1选择器进阶 1.1后代选择器 作用:根据html标签的嵌套关系,选择父元素后代中满足条件的元素 选择器语法:选择器1 选择器2 {css} 结果: 在选择器1所找到标签的后代中 注意: 后代包括…...
P2047 [NOI2007] 社交网络
Portal. 观察到数据范围 n ≤ 100 n\leq 100 n≤100,考虑用 Floyd。 在 Floyd 更新最短路的过程中,如果以当前结点为中转点的路径更新过,那么可以累加答案;否则,更新最短路径并重置答案。 统计答案时,枚…...
线性表的顺序存储
1.创建:实质是对data与length的修改 //定义一个线性表 typedef struct {int data[MaxSize];//存储线性表的元素 int length;//线性表的长度 }SqList; //新建一个表 void create(SqList &l){//传入地址才可以对其值进行改变 printf("请输入线性表的长度&…...
ChinaSoft 论坛巡礼 | 安全攸关软件的智能化开发方法论坛
2023年CCF中国软件大会(CCF ChinaSoft 2023)由CCF主办,CCF系统软件专委会、形式化方法专委会、软件工程专委会以及复旦大学联合承办,将于2023年12月1-3日在上海国际会议中心举行。 本次大会主题是“智能化软件创新推动数字经济与社…...
采用XML作为GUI描述语言
设计方案采用XML作为GUI描述语言的机制主要包括以下几个方面: 模型定义:使用XML定义GUI组件的模型,包括组件的名称、类型、属性、事件等。布局管理:使用XML定义GUI组件的布局,包括组件之间的相对位置、大小、对齐方式等。数据绑定:使用XML定义GUI组件的数据绑定方式,包括数据来…...
rust入门基础案例:猜数字游戏
案例出处是《Rust权威指南》,书中有更加详细的解释。从这个例子中,我们可以了解到 rust 的两个操作: 如何从控制台读取用户输入rust 如何生成随机数 代码格式化 编译器可在保存时对代码做格式化处理,底层调用 rustfmt 来实现&a…...
vue-cli5.0.x优雅降级,配置项目兼容旧版浏览器
兼容低版本谷歌浏览器 vue-cli5.0.x脚手架下的,如何降低项目版本以适用于底版本的浏览器。 直接使用默认配置打包部署出来的项目再40,60、70版本的谷歌浏览器跑不起来,蓝屏或者浏览器白屏一般这种情况都需要通过Babel去做转换,我…...
关于RabbitMQ的小总结
问题:消息在转换机无法被路由 发布确认高级作用在生产者发送到转换机,回退消息作用在消息在转换机无法被路由的情况(消息无法路由的意思是,消息在转换机没有匹配到对应的队列),进行消息回退,打…...
webgoat靶场攻关
A(5) Broken Access Control Insecure Direct Object References 直接对象引用 直接对象引用是指应用程序使用客户端提供的输入来访问数据和对象。 例子 使用 GET 方法的直接对象引用示例可能如下所示 https://some.company.tld/dor?id12345 https…...
BEV-YOLO 论文学习
1. 解决了什么问题? 出于安全和导航的目的,自驾感知系统需要全面而迅速地理解周围的环境。目前主流的研究方向有两个:第一种传感器融合方案整合激光雷达、相机和毫米波雷达,和第二种纯视觉方案。传感器融合方案的感知表现鲁棒&am…...
深入剖析AI大模型:大模型时代的 Prompt 工程全解析
今天聊的内容,我认为是AI开发里面非常重要的内容。它在AI开发里无处不在,当你对 AI 助手说 "用李白的风格写一首关于人工智能的诗",或者让翻译模型 "将这段合同翻译成商务日语" 时,输入的这句话就是 Prompt。…...
连锁超市冷库节能解决方案:如何实现超市降本增效
在连锁超市冷库运营中,高能耗、设备损耗快、人工管理低效等问题长期困扰企业。御控冷库节能解决方案通过智能控制化霜、按需化霜、实时监控、故障诊断、自动预警、远程控制开关六大核心技术,实现年省电费15%-60%,且不改动原有装备、安装快捷、…...
【HarmonyOS 5 开发速记】如何获取用户信息(头像/昵称/手机号)
1.获取 authorizationCode: 2.利用 authorizationCode 获取 accessToken:文档中心 3.获取手机:文档中心 4.获取昵称头像:文档中心 首先创建 request 若要获取手机号,scope必填 phone,permissions 必填 …...
Reasoning over Uncertain Text by Generative Large Language Models
https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829 1. 概述 文本中的不确定性在许多语境中传达,从日常对话到特定领域的文档(例如医学文档)(Heritage 2013;Landmark、Gulbrandsen 和 Svenevei…...
08. C#入门系列【类的基本概念】:开启编程世界的奇妙冒险
C#入门系列【类的基本概念】:开启编程世界的奇妙冒险 嘿,各位编程小白探险家!欢迎来到 C# 的奇幻大陆!今天咱们要深入探索这片大陆上至关重要的 “建筑”—— 类!别害怕,跟着我,保准让你轻松搞…...
[大语言模型]在个人电脑上部署ollama 并进行管理,最后配置AI程序开发助手.
ollama官网: 下载 https://ollama.com/ 安装 查看可以使用的模型 https://ollama.com/search 例如 https://ollama.com/library/deepseek-r1/tags # deepseek-r1:7bollama pull deepseek-r1:7b改token数量为409622 16384 ollama命令说明 ollama serve #:…...
MySQL 索引底层结构揭秘:B-Tree 与 B+Tree 的区别与应用
文章目录 一、背景知识:什么是 B-Tree 和 BTree? B-Tree(平衡多路查找树) BTree(B-Tree 的变种) 二、结构对比:一张图看懂 三、为什么 MySQL InnoDB 选择 BTree? 1. 范围查询更快 2…...
【C++】纯虚函数类外可以写实现吗?
1. 答案 先说答案,可以。 2.代码测试 .h头文件 #include <iostream> #include <string>// 抽象基类 class AbstractBase { public:AbstractBase() default;virtual ~AbstractBase() default; // 默认析构函数public:virtual int PureVirtualFunct…...
Java求职者面试指南:Spring、Spring Boot、Spring MVC与MyBatis技术解析
Java求职者面试指南:Spring、Spring Boot、Spring MVC与MyBatis技术解析 一、第一轮基础概念问题 1. Spring框架的核心容器是什么?它的作用是什么? Spring框架的核心容器是IoC(控制反转)容器。它的主要作用是管理对…...
python打卡day49@浙大疏锦行
知识点回顾: 通道注意力模块复习空间注意力模块CBAM的定义 作业:尝试对今天的模型检查参数数目,并用tensorboard查看训练过程 一、通道注意力模块复习 & CBAM实现 import torch import torch.nn as nnclass CBAM(nn.Module):def __init__…...
