012_py之证书过期监测及域名使用的py列表的并集差集交集

一、由于线上域名证书快要过期,需要进行监测,顾写了一个方法用于线上证书过期监测,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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}\t{1}\t{2}'.format(domain, cert['issuer'][2][0][1], cert['notAfter'])
 
def main():
    print check_domain_sslexpired("www.jyall.com")
if __name__ == '__main__':
    main()

输出=>

1
www.jyall.com   GlobalSign Organization Validation CA - SHA256 - G2 Apr 11 05:16:03 2019 GMT

二、由于域名数量特别地多,所以需要使用集合进行对已经更新的和未更新的域名进行统计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/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()

输出:

1
2
3
4
5
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]

 

posted @   arun_python  阅读(155)  评论(0编辑  收藏  举报
编辑推荐:
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
阅读排行:
· 编程神器Trae:当我用上后,才知道自己的创造力被低估了多少
· 开发的设计和重构,为开发效率服务
· 从零开始开发一个 MCP Server!
· Ai满嘴顺口溜,想考研?浪费我几个小时
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
点击右上角即可分享
微信分享提示