可以直接给他一个开通了ssl证书的网站域名,就能算出ssl证书是否过期,还剩多少天,适合ssl证书远程监控报警,代码如下:
import ssl import socket from datetime import datetime def check_ssl_expiry(hostname, port=443): ssl_context = ssl.create_default_context() conn = ssl_context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=hostname) # 3秒应该足以建立连接 conn.settimeout(3.0) try: conn.connect((hostname, port)) ssl_info = conn.getpeercert() except Exception as e: print(f"Error: {e}") return None finally: conn.close() # 获取证书的过期时间 expire_date = datetime.strptime(ssl_info['notAfter'], '%b %d %H:%M:%S %Y %Z') # 当前时间 current_date = datetime.utcnow() # 打印剩余天数 days_remaining = (expire_date - current_date).days return days_remaining # 测试函数,查看www.example.com的证书有效期 days_left = check_ssl_expiry('www.bfw.wiki') if days_left is not None: if days_left > 0: print(f"The SSL certificate will expire in {days_left} days.") else: print("The SSL certificate has expired or is about to expire.")
网友回复
js如何流式输出ai的回答并折叠代码块,点击代码块右侧可预览代码?
ai大模型如何将文章转换成可视化一目了然的图片流程图图表?
大模型生成html版本的ui原型图和ppt演示文档的系统提示词怎么写?
rtsp视频直播流如何转换成websocket流在h5页面上观看?
为啥coze会开源工作流agent coze studio?
如何检测网页是通过收藏夹打开的?
python如何实现类似php的http动态脚本请求处理响应代码?
js如何实现类似php的http动态脚本请求处理响应代码?
trae与solo有啥区别不同?
vue如何让ai动态生成问卷调查多步骤表单式收集基础信息自动规划执行任务?