您的位置 首页 golang

使用 golang 内置模块实现网站TLS证书过期日期查询

由于前段时间出现过大公司域名证书未及时更新导致服务中断,之前也有了解过 golang。闲来无事,于是用了半天的时间,通过 golang 官网文档,写了一个小工具,来获取域名证书的到期时间。

证书信息

通过传参 -d 域名 来获取本地时区的证书过期时间

 ➜  tls-cert-expire git:(master) ✗ ./tls-cert-expire -d www.io-notes.com
2020-06-24 08:19:05 +0800 CST  

通过参数 -s 可以获取过期日期的时间戳,方便其他脚本调用进行计算告警

 ➜  tls-cert-expire git:(master) ✗ ./tls-cert-expire -d www.io-notes.com -s
1592957945  

其他参数,默认超时为 5s ,https 端口为 443

 ➜  tls-cert-expire git:(master) ✗ ./tls-cert-expire -h
Usage 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)  

时间戳转化工具:

编译好的 二进制 包下载地址:

源码:

可对源码稍加修改,可获取更多证书信息。

文章来源:智云一二三科技

文章标题:使用 golang 内置模块实现网站TLS证书过期日期查询

文章地址:https://www.zhihuclub.com/86243.shtml

关于作者: 智云科技

热门文章

网站地图