原理:使用go提供的模块 crypto/tls
,可以获取域名证书的信息,通过到期时间可以判断证书是否过期
package main import ( "crypto/tls" "fmt" ) func main() { conn, _ := tls.Dial("tcp", "www.baidu.com:443", nil) cert := conn.ConnectionState().PeerCertificates[0] // 时间信息 fmt.Printf("NotBefore: %v\n", cert.NotBefore) // NotBefore: 2022-07-05 05:16:02 +0000 UTC fmt.Printf("NotAfter: %v\n", cert.NotAfter) // NotAfter: 2023-08-06 05:16:01 +0000 UTC // 其他信息 fmt.Printf("IPAddresses: %v\n", cert.IPAddresses) // IPAddresses: [] fmt.Printf("IPAddresses: %v\n", conn.RemoteAddr()) // IPAddresses: 220.181.38.150:443 fmt.Printf("Version: %v\n", cert.Version) fmt.Printf("SerialNumber: %v\n", cert.SerialNumber) fmt.Printf("Issuer: %v\n", cert.Issuer) fmt.Printf("Subject: %v\n", cert.Subject) }
Python实现的可视化工具:
Domain Admin:基于Python + Vue.js 技术栈实现的域名SSL证书监测平台
参考