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

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - 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证书检查完成!"