原理:使用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) 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实现的可视化工具