从阿里云获取所有域名解析:

    1. #! /data/devops/py3.7env/bin/python
    2. # -*- coding:utf-8 -*-
    3. # Author: yau
    4. ##此脚本用来获取https证书过期时间,需要先执行pip install aliyun-python-sdk-core aliyun-python-sdk-alidns pyyaml
    5. from aliyunsdkcore.client import AcsClient
    6. profile = {
    7. "accessKeyId": "xx",
    8. "accessKeySecret": "xx",
    9. "regionId": "cn-hangzhou"
    10. }
    11. from aliyunsdkalidns.request.v20150109.DescribeDomainRecordsRequest import DescribeDomainRecordsRequest
    12. import json
    13. import os
    14. import sys
    15. def describe_domain_records(client, record_type, subdomain):
    16. request = DescribeDomainRecordsRequest()
    17. request.set_accept_format('json')
    18. request.set_Type(record_type)
    19. request.set_DomainName(subdomain)
    20. request.set_PageSize(500)
    21. response = client.do_action_with_exception(request)
    22. response = str(response, encoding='utf-8')
    23. result = json.loads(response)
    24. return result
    25. client = AcsClient(profile["accessKeyId"], profile["accessKeySecret"], profile["regionId"])
    26. des_result = describe_domain_records(client, sys.argv[1], sys.argv[2])
    27. for domain in des_result['DomainRecords']['Record']:
    28. os.system('echo ' + domain['RR']+'.'+domain['DomainName'] + ' >> domain-aliyun.txt')
    29. # python get.py A xxx.com

    查询域名证书是否过期脚本:

    1. #! /data/devops/py3.7env/bin/python
    2. # -*- coding:utf-8 -*-
    3. # Author: yau
    4. ##此脚本用来获取https证书过期时间,需要先执行pip install pyopenssl
    5. import argparse;
    6. from urllib3.contrib import pyopenssl as reqs;
    7. from datetime import datetime;
    8. #命令行参数
    9. parser = argparse.ArgumentParser(description='本脚本获取https证书到期时间');
    10. parser.add_argument('-w', '-www', metavar='https网站,如www.xxx.com',required=True, dest='sites', nargs='+', help='输入监控的https网站')
    11. args = parser.parse_args()
    12. #公网验证
    13. def get_notafter(www):
    14. cert = reqs.OpenSSL.crypto.load_certificate(reqs.OpenSSL.crypto.FILETYPE_PEM, reqs.ssl.get_server_certificate((www, 443)));
    15. notafter = datetime.strptime(cert.get_notAfter().decode()[0:-1], '%Y%m%d%H%M%S');
    16. remain_days = notafter - datetime.now();
    17. print(www,'['+str(remain_days.days)+']');
    18. #输出结果
    19. try:
    20. for site in args.sites:
    21. get_notafter(site);
    22. except Exception as e:
    23. print(site,"[Invalid address]");
    24. #for site in args.sites:
    25. # get_notafter(site);

    循环检查域名shell脚本

    1. #/bin/bash
    2. for i in `cat domain-aliyun.txt`
    3. do
    4. echo "${i}" | grep "^#" &> /dev/null
    5. if [ "$?" == 0 ];then
    6. continue
    7. fi
    8. time=`./sslooker -w ${i}`
    9. echo ${time}
    10. echo ${time} | grep 'Invalid address' &> /dev/null
    11. if [ "$?" != "0" ];then
    12. days=`echo ${time} | awk -F' ' '{print $NF}' | sed 's/\[//g' | sed 's/\]//g'`
    13. if [ $days -lt 15 ];then
    14. echo 1 > ssl_status
    15. exit 1
    16. fi
    17. fi
    18. done
    19. echo 0 > ssl_status