由于前段时间出现过大公司域名证书未及时更新导致服务中断,之前也有了解过 golang。闲来无事,于是用了半天的时间,通过 golang 官网文档,写了一个小工具,来获取域名证书的到期时间。
通过传参 -d 域名 来获取本地时区的证书过期时间
➜ tls-cert-expire git:(master) ✗ ./tls-cert-expire -d www.io-notes.com2020-06-24 08:19:05 +0800 CST
通过参数 -s 可以获取过期日期的时间戳,方便其他脚本调用进行计算告警
➜ tls-cert-expire git:(master) ✗ ./tls-cert-expire -d www.io-notes.com -s1592957945
其他参数,默认超时为 5s ,https 端口为 443
➜ tls-cert-expire git:(master) ✗ ./tls-cert-expire -hUsage of ./tls-cert-expire: -d domain domain: 域名 IP -p port port : 端口 (default 443) -s seconds since 1970-01-01 00:00:00 UTC -t timeout timeout : 连接超时 (default 5)
时间戳转化工具: https://www.io-notes.com/tools/timestamp.html
编译好的二进制包下载地址: https://github.com/io-notes/tls-cert-expire/releases
源码: https://github.com/io-notes/tls-cert-expire/blob/master/tls-cert-expire.go
可对源码稍加修改,可获取更多证书信息。