一、由于线上域名证书快要过期,需要进行监测,顾写了一个方法用于线上证书过期监测,如下:
import ssl,socket,pprint def check_domain_sslexpired(domain): context = ssl.create_default_context() context.verify_mode = ssl.CERT_REQUIRED context.check_hostname = True context.load_verify_locations("/private/tmp/creditupdate/jyall.crt") conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain) conn.connect((domain, 443)) cert = conn.getpeercert() return '{0} {1} {2}'.format(domain, cert['issuer'][2][0][1], cert['notAfter']) def main(): print check_domain_sslexpired("www.jyall.com") if __name__ == '__main__': main()
输出=>
www.jyall.com GlobalSign Organization Validation CA - SHA256 - G2 Apr 11 05:16:03 2019 GMT
二、由于域名数量特别地多,所以需要使用集合进行对已经更新的和未更新的域名进行统计
#!/usr/bin/env python #coding:utf-8 def diff(listA,listB): #求交集的两种方式 retA = [i for i in listA if i in listB] retB = list(set(listA).intersection(set(listB))) print "retA is: ",retA print "retB is: ",retB #求并集 retC = list(set(listA).union(set(listB))) print "retC1 is: ",retC #求差集,在B中但不在A中 retD = list(set(listB).difference(set(listA))) print "retD is: ",retD retE = [i for i in listB if i not in listA] print "retE is: ",retE def main(): listA = [1,2,3,4,5] listA1 = [3,4,5] listB = [3,4,5,6,7] diff(listA,listB) if __name__ == '__main__': main()
输出:
retA is: [3, 4, 5] retB is: [3, 4, 5] retC1 is: [1, 2, 3, 4, 5, 6, 7] retD is: [6, 7] retE is: [6, 7]