vjpg
ssl socket:

import ssl, socket

hostname = 'www.baidu.com'
c = ssl.create_default_context()
s = c.wrap_socket(socket.socket(), server_hostname=hostname)
s.connect((hostname, 443))
cert = s.getpeercert()

OpenSSL:

import ssl
import time
import OpenSSL
hostname = 'www.baidu.com'
port = 443
cert = ssl.get_server_certificate((hostname, port)).encode()
cert_obj = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
cert_time = int(time.strftime('%s', time.strptime(cert_obj.get_notAfter().decode(), '%Y%m%d%H%M%SZ')))

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code