惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
N
News | PayPal Newsroom
V2EX - 技术
V2EX - 技术
博客园 - 【当耐特】
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
有赞技术团队
有赞技术团队
S
Schneier on Security
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
IT之家
IT之家
Project Zero
Project Zero
博客园 - 司徒正美
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Security Latest
Security Latest
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity

博客园 - sherlock-merlin

Windows官方ISO镜像下载(11、10、8.1、7、Vista、XP、server) VmwareWorkstation历史版本网盘备份 TP-Link SSH密码分析(claude) 2025 年主流 Linux 发行版全览 将树莓派2打造成复古游戏机——完整刷机指南 Tenda W30EV2.0 官改固件 分享一个windows平台的aigc创作工具,支持Nano Banana 2、sora2等 win11无法打开海康摄像头管理页面,提示请用IE浏览器打开 joyagent部署笔记 Microsoft Office 家庭学生版(2013、2016、2019、2021、2024 ) ucloud印度孟买服务器简单测试 ucloud菲律宾马尼拉服务器简单测试 电信光猫中兴ZXEN G100S(天翼政企网关)端口转发逻辑感人 liblib蜜汁优化 前端PDF工具箱 linux服务器开启BBR加速 驾考模拟器v1.0 竖版视频左右拼接工具 用winform实现的nginx日志分析软件 图片自动去黑边工具 c#给图片添加边框 Postman最后一个免登录的版本下载 html录音机 adobe photoshop 2024提示 This unlicensed Adobe app has been disabled 一个windows防火墙管理器
使用bash脚本检测网站SSL证书是否过期
sherlock-merlin · 2025-09-17 · via 博客园 - sherlock-merlin
#!/bin/bash

# 加载环境变量
. /etc/profile
. ~/.bash_profile
. /etc/bashrc

# 脚本所在目录即脚本名称
script_dir=$( cd "$( dirname "$0"  )" && pwd )
script_name=$(basename ${0})
readFile="${script_dir}/domain_ssl.info"

# 检查配置文件是否存在
if [ ! -f "${readFile}" ]; then
    echo "错误:配置文件 ${readFile} 不存在"
    exit 1
fi

grep -v '^#' ${readFile} | while read line; do
    # 跳过空行
    if [[ -z "${line// }" ]]; then
        continue
    fi
    
    # 处理域名和端口
    if [[ "${line}" == *":"* ]]; then
        # 包含端口号
        get_domain=$(echo "${line}" | awk -F ':' '{print $1}')
        get_port=$(echo "${line}" | awk -F ':' '{print $2}')
    else
        # 不包含端口号,使用默认443
        get_domain=${line}
        get_port=443
    fi
    
    # 去除域名和端口中的空格
    get_domain=$(echo "${get_domain}" | tr -d ' ')
    get_port=$(echo "${get_port}" | tr -d ' ')
    
    # 验证端口号是否为数字
    if ! [[ "${get_port}" =~ ^[0-9]+$ ]]; then
        echo "警告:域名 ${get_domain} 的端口 ${get_port} 不是有效数字,使用默认端口443"
        get_port=443
    fi
    
    echo "正在检查 ${get_domain}:${get_port} 的SSL证书..."
    
    # 使用openssl获取域名的证书情况,然后获取其中的到期时间
    END_TIME=$(echo | openssl s_client -servername ${get_domain} -connect ${get_domain}:${get_port} 2>/dev/null | openssl x509 -noout -dates | grep 'After' | awk -F '=' '{print $2}' | awk -F ' +' '{print $1,$2,$4 }')
    
    # 检查是否成功获取到证书信息
    if [[ -z "${END_TIME}" ]]; then
        echo "错误:无法获取 ${get_domain}:${get_port} 的SSL证书信息"
        # 发送错误通知(钉钉、飞书)
        curl -s -o /dev/null 'https://oapi.dingtalk.com/robot/send?access_token=xxxx' -H 'Content-Type: application/json' -d '{"msgtype": "text", "text": {"content": "'"${get_domain}:${get_port} SSL证书检查失败,请手动检查"'"}}'
        curl -s -o /dev/null -X POST -H "Content-Type: application/json" 'https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' -d '{"msg_type":"text","content":{"text":"'"${get_domain}:${get_port} SSL证书检查失败,请手动检查"'"}}'
        continue
    fi
    
    END_TIME1=$(date +%s -d "$END_TIME") # 将日期转化为时间戳
    NOW_TIME=$(date +%s -d "$(date "+%Y-%m-%d %H:%M:%S")") # 将当前的日期也转化为时间戳
    RST=$(($(($END_TIME1 - $NOW_TIME))/(60*60*24))) # 到期时间减去目前时间再转化为天数
    
    echo "域名:${get_domain}:${get_port} | 证书有效天数剩余:${RST} 天"
    
    # 证书过期提醒
    if [ $RST -lt 10 ]; then
        echo "警告:${get_domain}:${get_port} 证书将在 ${RST} 天后过期!"
        # 钉钉通知
        curl -s -o /dev/null 'https://oapi.dingtalk.com/robot/send?access_token=xxxx' \
            -H 'Content-Type: application/json' \
            -d '{"msgtype": "text", "text": {"content": "'"${get_domain}:${get_port} HTTPS证书有效期少于10天(剩余${RST}天),存在风险,请及时更新证书"'"}}'
        
        # 飞书通知
        curl -s -o /dev/null -X POST \
            -H "Content-Type: application/json" \
            'https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' \
            -d '{"msg_type":"text","content":{"text":"https://'"${get_domain}:${get_port}"' SSL证书有效期为'"${RST}"'天,请注意及时更新"}}'
    fi
done

echo "SSL证书检查完成!"