31 lines
588 B
Go
31 lines
588 B
Go
package httpsx
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// 获取HTTPS证书过期时间
|
|
|
|
func main() {
|
|
tr := &http.Transport{
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
}
|
|
client := &http.Client{Transport: tr}
|
|
|
|
seedUrl := "https://www.baidu.cn"
|
|
resp, err := client.Get(seedUrl)
|
|
defer resp.Body.Close()
|
|
|
|
if err != nil {
|
|
fmt.Errorf(seedUrl, " 请求失败")
|
|
panic(err)
|
|
}
|
|
|
|
//fmt.Println(resp.TLS.PeerCertificates[0])
|
|
certInfo := resp.TLS.PeerCertificates[0]
|
|
fmt.Println("过期时间:", certInfo.NotAfter)
|
|
fmt.Println("组织信息:", certInfo.Subject)
|
|
}
|