设置超时

This commit is contained in:
Jing Ling
2020-08-22 01:42:30 +08:00
parent 786df87bdc
commit e53a77d81a
+5 -5
View File
@@ -12,7 +12,6 @@ class CertInfo(Check):
def __init__(self, domain): def __init__(self, domain):
Check.__init__(self) Check.__init__(self)
self.domain = domain self.domain = domain
self.port = 443
self.module = 'check' self.module = 'check'
self.source = 'CertInfo' self.source = 'CertInfo'
@@ -22,10 +21,11 @@ class CertInfo(Check):
""" """
try: try:
ctx = ssl.create_default_context() ctx = ssl.create_default_context()
sock = ctx.wrap_socket(socket.socket(), sock = socket.socket()
server_hostname=self.domain) sock.settimeout(10)
sock.connect((self.domain, self.port)) wrap_sock = ctx.wrap_socket(sock, server_hostname=self.domain)
cert_dict = sock.getpeercert() wrap_sock.connect((self.domain, 443))
cert_dict = wrap_sock.getpeercert()
except Exception as e: except Exception as e:
logger.log('DEBUG', e.args) logger.log('DEBUG', e.args)
return return