欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python腳本監(jiān)聽域名證書過(guò)期時(shí)間并通知消息到釘釘(最新推薦)

 更新時(shí)間:2023年11月03日 15:05:47   作者:yunson_Liu  
這篇文章主要介紹了python腳本監(jiān)聽域名證書過(guò)期時(shí)間并通知消息到釘釘(最新推薦),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

版本一:

執(zhí)行腳本帶上 --dingtalk-webhook和–domains后指定釘釘token和域名

python3 ssl_spirtime.py --dingtalk-webhook https://oapi.dingtalk.com/robot/send?access_token=avd345324 --domains www.abc1.com www.abc2.com www.abc3.com

腳本如下

#!/usr/bin/python3
import ssl
import socket
from datetime import datetime
import argparse
import requests
def get_ssl_cert_expiration(domain, port=443):
    context = ssl.create_default_context()
    conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)
    conn.connect((domain, port))
    cert = conn.getpeercert()
    conn.close()
    # Extract the expiration date from the certificate
    not_after = cert['notAfter']
    # Convert the date string to a datetime object
    expiration_date = datetime.strptime(not_after, '%b %d %H:%M:%S %Y %Z')
    return expiration_date
def send_dingtalk_message(webhook_url, message):
    headers = {'Content-Type': 'application/json'}
    payload = {
        "msgtype": "text",
        "text": {
            "content": message
        }
    }
    response = requests.post(webhook_url, json=payload, headers=headers)
    if response.status_code == 200:
        print("Message sent successfully to DingTalk")
    else:
        print(f"Failed to send message to DingTalk. HTTP Status Code: {response.status_code}")
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Test SSL certificate expiration for multiple domains")
    parser.add_argument("--dingtalk-webhook", required=True, help="DingTalk webhook URL")
    parser.add_argument("--domains", nargs='+', required=True, help="List of domains to test SSL certificate expiration")
    args = parser.parse_args()
    for domain in args.domains:
        expiration_date = get_ssl_cert_expiration(domain)
        current_date = datetime.now()
        days_remaining = (expiration_date - current_date).days
        print(f"SSL certificate for {domain} expires on {expiration_date}")
        print(f"Days remaining: {days_remaining} days")
        if days_remaining < 300:
            message = f"SSL certificate for {domain} will expire on {expiration_date}. Only {days_remaining} days remaining."
            send_dingtalk_message(args.dingtalk_webhook, message)

版本二

執(zhí)行腳本帶上 --dingtalk-webhook、–secret和–domains后指定釘釘token、密鑰和域名

python3 ssl_spirtime4.py --dingtalk-webhook https://oapi.dingtalk.com/robot/send?access_token=abdcsardaef--secret SEC75bcc2abdfd --domains www.abc1.com www.abc2.com www.abc3.com
#!/usr/bin/python3
import ssl
import socket
from datetime import datetime
import argparse
import requests
import hashlib
import hmac
import base64
import time
def get_ssl_cert_expiration(domain, port=443):
    context = ssl.create_default_context()
    conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)
    conn.connect((domain, port))
    cert = conn.getpeercert()
    conn.close()
    # Extract the expiration date from the certificate
    not_after = cert['notAfter']
    # Convert the date string to a datetime object
    expiration_date = datetime.strptime(not_after, '%b %d %H:%M:%S %Y %Z')
    return expiration_date
def send_dingtalk_message(webhook_url, secret, message):
    headers = {'Content-Type': 'application/json'}
    # Get the current timestamp in milliseconds
    timestamp = str(int(round(time.time() * 1000)))
    # Combine timestamp and secret to create a sign string
    sign_string = f"{timestamp}\n{secret}"
    # Calculate the HMAC-SHA256 signature
    sign = base64.b64encode(hmac.new(secret.encode(), sign_string.encode(), hashlib.sha256).digest()).decode()
    # Create the payload with the calculated signature
    payload = {
        "msgtype": "text",
        "text": {
            "content": message
        },
        "timestamp": timestamp,
        "sign": sign
    }
    response = requests.post(f"{webhook_url}&timestamp={timestamp}&sign={sign}", json=payload, headers=headers)
    if response.status_code == 200:
        print("Message sent successfully to DingTalk")
    else:
        print(f"Failed to send message to DingTalk. HTTP Status Code: {response.status_code}")
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Test SSL certificate expiration for multiple domains")
    parser.add_argument("--dingtalk-webhook", required=True, help="DingTalk webhook URL")
    parser.add_argument("--secret", required=True, help="DingTalk robot secret")
    parser.add_argument("--domains", nargs='+', required=True, help="List of domains to test SSL certificate expiration")
    args = parser.parse_args()
    for domain in args.domains:
        expiration_date = get_ssl_cert_expiration(domain)
        current_date = datetime.now()
        days_remaining = (expiration_date - current_date).days
        print(f"SSL certificate for {domain} expires on {expiration_date}")
        print(f"Days remaining: {days_remaining} days")
        if days_remaining < 10:
            message = f"SSL certificate for {domain} will expire on {expiration_date}. Only {days_remaining} days remaining."
            send_dingtalk_message(args.dingtalk_webhook, args.secret, message)

終極版本

python執(zhí)行腳本時(shí)指定配置文件

python3 ssl_spirtime.py --config-file config.json

config.json配置文件內(nèi)容如下

{
    "dingtalk-webhook": "https://oapi.dingtalk.com/robot/send?access_token=avbdcse345dd",
    "secret": "SECaegdDEdaDSEGFdadd12334",
    "domains": [
        "www.a.tel",
        "www.b.com",
        "www.c.app",
        "www.d-cn.com",
        "www.e.com",
        "www.f.com",
        "www.g.com",
        "www.gg.com",
        "www.sd.com",
        "www.234.com",
        "www.456.com",
        "www.addf.com",
        "www.advdwd.com",
        "aqjs.aefdsdf.com",
        "apap.adedgdg.com",
        "cbap.asfew.com",
        "ksjsw.adfewfd.cn",
        "wdxl.aeffadaf.com",
        "wspr.afefd.shop",
        "sktprd.daeafsdf.shop",
        "webskt.afaefafa.shop",
        "www.afaead.cn",
        "www.afewfsegs.co",
        "www.aaeafsf.com",
        "bdvt.aeraf.info",
        "dl.afawef.co",
        "dl.aefarge.com"
    ]
}

腳本內(nèi)容如下

#!/usr/bin/python3
import ssl
import socket
from datetime import datetime
import argparse
import requests
import hashlib
import hmac
import base64
import time
import json
def get_ssl_cert_expiration(domain, port=443):
    context = ssl.create_default_context()
    conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)
    conn.connect((domain, port))
    cert = conn.getpeercert()
    conn.close()
    # Extract the expiration date from the certificate
    not_after = cert['notAfter']
    # Convert the date string to a datetime object
    expiration_date = datetime.strptime(not_after, '%b %d %H:%M:%S %Y %Z')
    return expiration_date
def send_dingtalk_message(webhook_url, secret, message):
    headers = {'Content-Type': 'application/json'}
    # Get the current timestamp in milliseconds
    timestamp = str(int(round(time.time() * 1000)))
    # Combine timestamp and secret to create a sign string
    sign_string = f"{timestamp}\n{secret}"
    # Calculate the HMAC-SHA256 signature
    sign = base64.b64encode(hmac.new(secret.encode(), sign_string.encode(), hashlib.sha256).digest()).decode()
    # Create the payload with the calculated signature
    payload = {
        "msgtype": "text",
        "text": {
            "content": message
        },
        "timestamp": timestamp,
        "sign": sign
    }
    response = requests.post(f"{webhook_url}&timestamp={timestamp}&sign={sign}", json=payload, headers=headers)
    if response.status_code == 200:
        print("Message sent successfully to DingTalk")
    else:
        print(f"Failed to send message to DingTalk. HTTP Status Code: {response.status_code}")
if __name__ == "__main__":
    # 從配置文件中加載配置
    with open("config.json", 'r') as config_file:
        config = json.load(config_file)
    dingtalk_webhook = config.get("dingtalk-webhook")
    secret = config.get("secret")
    domains = config.get("domains")
    for domain in domains:
        expiration_date = get_ssl_cert_expiration(domain)
        current_date = datetime.now()
        days_remaining = (expiration_date - current_date).days
        print(f"SSL certificate for {domain} expires on {expiration_date}")
        print(f"Days remaining: {days_remaining} days")
        if days_remaining < 10:
            message = f"SSL certificate for {domain} will expire on {expiration_date}. Only {days_remaining} days remaining."
            send_dingtalk_message(dingtalk_webhook, secret, message)

執(zhí)行結(jié)果

/usr/bin/python3 /root/ssl_spirtime.py --config-file /root/config.json
SSL certificate for www.a.tel expires on 2024-06-08 23:59:59
Days remaining: 220 days
SSL certificate for www.b.com expires on 2024-05-23 07:45:13
Days remaining: 203 days
SSL certificate for www.c.app expires on 2024-05-23 07:45:13
Days remaining: 203 days
SSL certificate for www.d-cn.com expires on 2024-03-03 00:00:00
Days remaining: 122 days
SSL certificate for www.aed.com expires on 2024-11-17 06:30:15
Days remaining: 381 days
SSL certificate for www.afedf.com expires on 2024-06-20 23:59:59
Days remaining: 232 days
SSL certificate for www.aefdfd.com expires on 2024-06-20 23:59:59

釘釘告警消息如下

到此這篇關(guān)于python腳本監(jiān)聽域名證書過(guò)期時(shí)間,并將通知消息到釘釘?shù)奈恼戮徒榻B到這了,更多相關(guān)python域名證書過(guò)期時(shí)間內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python爬取51job中hr的郵箱

    python爬取51job中hr的郵箱

    這篇文章主要為大家詳細(xì)介紹了python爬取51job中hr的郵箱的相關(guān)資料,需要的朋友可以參考下
    2016-05-05
  • 詳解Python自動(dòng)化之文件自動(dòng)化處理

    詳解Python自動(dòng)化之文件自動(dòng)化處理

    今天給大家?guī)?lái)的是關(guān)于Python的相關(guān)知識(shí),文章圍繞著Python文件自動(dòng)化處理展開,文中有非常詳細(xì)的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • Python函數(shù)調(diào)用的幾種方式(類里面,類之間,類外面)

    Python函數(shù)調(diào)用的幾種方式(類里面,類之間,類外面)

    本文主要介紹了Python函數(shù)調(diào)用的幾種方式(類里面,類之間,類外面),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • Pandas DataFrame如何按照一列數(shù)據(jù)的特定順序進(jìn)行排序

    Pandas DataFrame如何按照一列數(shù)據(jù)的特定順序進(jìn)行排序

    這篇文章主要介紹了Pandas DataFrame如何按照一列數(shù)據(jù)的特定順序進(jìn)行排序,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • 利用python編寫一個(gè)圖片主色轉(zhuǎn)換的腳本

    利用python編寫一個(gè)圖片主色轉(zhuǎn)換的腳本

    這篇文章主要給大家介紹了關(guān)于利用python編寫一個(gè)圖片主色轉(zhuǎn)換腳本的相關(guān)資料,主要使用的是Python中的Pillow圖像處理庫(kù),文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起看看吧。
    2017-12-12
  • Python與機(jī)器學(xué)習(xí)庫(kù)LightGBM使用詳解

    Python與機(jī)器學(xué)習(xí)庫(kù)LightGBM使用詳解

    LightGBM是一種高效的梯度提升決策樹框架,以其快速訓(xùn)練和高預(yù)測(cè)性能聞名,它通過(guò)直方圖算法和基于葉子生長(zhǎng)策略優(yōu)化技術(shù),能夠在大規(guī)模數(shù)據(jù)集上提供卓越性能,本文詳細(xì)介紹了如何使用LightGBM進(jìn)行分類和回歸任務(wù),包括模型構(gòu)建、參數(shù)調(diào)整
    2025-01-01
  • Django2.2配置xadmin的實(shí)現(xiàn)

    Django2.2配置xadmin的實(shí)現(xiàn)

    這篇文章主要介紹了Django2.2配置xadmin的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Python使用openpyxl批量處理數(shù)據(jù)

    Python使用openpyxl批量處理數(shù)據(jù)

    openpyxl 是一個(gè)用于處理 xlsx 格式Excel表格文件的第三方python庫(kù),其支持Excel表格絕大多數(shù)基本操作。本文給大家介紹Python使用openpyxl批量處理數(shù)據(jù)的操作方法,感興趣的朋友一起看看吧
    2021-06-06
  • Python中優(yōu)雅處理JSON文件的方法實(shí)例

    Python中優(yōu)雅處理JSON文件的方法實(shí)例

    JSON是一種輕量級(jí)的數(shù)據(jù)交換格式,JSON采用完全獨(dú)立于語(yǔ)言的文本格式,但是也使用了類似于C語(yǔ)言家族的習(xí)慣,這篇文章主要給大家介紹了關(guān)于Python中優(yōu)雅處理JSON文件的相關(guān)資料,需要的朋友可以參考下
    2021-12-12
  • Python中語(yǔ)音轉(zhuǎn)文字相關(guān)庫(kù)介紹(最新推薦)

    Python中語(yǔ)音轉(zhuǎn)文字相關(guān)庫(kù)介紹(最新推薦)

    Python的speech_recognition庫(kù)是一個(gè)用于語(yǔ)音識(shí)別的Python包,它可以使Python程序能夠識(shí)別和翻譯來(lái)自麥克風(fēng)、音頻文件或網(wǎng)絡(luò)流的語(yǔ)音,這篇文章主要介紹了Python中語(yǔ)音轉(zhuǎn)文字相關(guān)庫(kù)介紹,需要的朋友可以參考下
    2023-05-05

最新評(píng)論