最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

版本一:

執(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í)行腳本時指定配置文件

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)聽域名證書過期時間,并將通知消息到釘釘?shù)奈恼戮徒榻B到這了,更多相關(guān)python域名證書過期時間內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python快速排序的實現(xiàn)及運行時間比較

    python快速排序的實現(xiàn)及運行時間比較

    這篇文章主要介紹了python快速排序的實現(xiàn)及運行時間比較,本文通過兩種方法給大家介紹,大家可以根據(jù)自己需要選擇適合自己的方法,對python實現(xiàn)快速排序相關(guān)知識感興趣的朋友一起看看吧
    2019-11-11
  • Python加密word文檔詳解

    Python加密word文檔詳解

    這篇文章主要介紹了Python實現(xiàn)對word文檔添加密碼去除密碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • selenium+python實現(xiàn)1688網(wǎng)站驗證碼圖片的截取功能

    selenium+python實現(xiàn)1688網(wǎng)站驗證碼圖片的截取功能

    這篇文章主要介紹了selenium+python實現(xiàn)1688網(wǎng)站驗證碼圖片的截取,需要的朋友可以參考下
    2018-08-08
  • python調(diào)用MySql保姆級圖文教程(包會的)

    python調(diào)用MySql保姆級圖文教程(包會的)

    MySQL是當今市場上最受歡迎的數(shù)據(jù)庫系統(tǒng)之一,由于大多數(shù)應(yīng)用程序需要以某種形式與數(shù)據(jù)交互,因此像Python這樣的編程語言提供了用于存儲和訪問這些數(shù)據(jù)的工具,這篇文章主要給大家介紹了關(guān)于python調(diào)用MySql的相關(guān)資料,需要的朋友可以參考下
    2024-12-12
  • Anaconda和ipython環(huán)境適配的實現(xiàn)

    Anaconda和ipython環(huán)境適配的實現(xiàn)

    這篇文章主要介紹了Anaconda和ipython環(huán)境適配的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • Python實現(xiàn)讀取SQLServer數(shù)據(jù)并插入到MongoDB數(shù)據(jù)庫的方法示例

    Python實現(xiàn)讀取SQLServer數(shù)據(jù)并插入到MongoDB數(shù)據(jù)庫的方法示例

    這篇文章主要介紹了Python實現(xiàn)讀取SQLServer數(shù)據(jù)并插入到MongoDB數(shù)據(jù)庫的方法,涉及Python同時進行SQLServer與MongoDB數(shù)據(jù)庫的連接、查詢、讀取、寫入等相關(guān)操作實現(xiàn)技巧,需要的朋友可以參考下
    2018-06-06
  • Python高效實現(xiàn)Excel與TXT文本文件之間的數(shù)據(jù)轉(zhuǎn)換

    Python高效實現(xiàn)Excel與TXT文本文件之間的數(shù)據(jù)轉(zhuǎn)換

    Excel 文件和文本文件(TXT)在不同場景中各有優(yōu)勢,本文將通過實際操作,演示如何使用 Python 來實現(xiàn) Excel 和 TXT 文件之間的數(shù)據(jù)轉(zhuǎn)換,幫助你輕松掌握這一常見且實用的技巧
    2025-10-10
  • 如何建立一個超圖詳解

    如何建立一個超圖詳解

    這篇文章主要介紹了如何建立一個超圖,如果你想學(xué)習(xí)圖像處理,這盤文章可能對你有一點幫助,需要的朋友可以參考下
    2021-04-04
  • 對Python 多線程統(tǒng)計所有csv文件的行數(shù)方法詳解

    對Python 多線程統(tǒng)計所有csv文件的行數(shù)方法詳解

    今天小編就為大家分享一篇對Python 多線程統(tǒng)計所有csv文件的行數(shù)方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-02-02
  • 基于Python實現(xiàn)的車牌識別系統(tǒng)

    基于Python實現(xiàn)的車牌識別系統(tǒng)

    本文將以基于Python的車牌識別系統(tǒng)實現(xiàn)為方向,介紹車牌識別技術(shù)的基本原理、常用算法和方法,并詳細講解如何利用Python語言實現(xiàn)一個完整的車牌識別系統(tǒng),需要的朋友可以參考下
    2023-10-10

最新評論

陆丰市| 甘洛县| 公安县| 咸丰县| 尼木县| 和龙市| 黎城县| 青浦区| 营山县| 黄龙县| 金平| 金川县| 蓝山县| 陆川县| 临沂市| 五常市| 宁河县| 兴仁县| 绥德县| 宜黄县| 策勒县| 寻乌县| 锦州市| 波密县| 武邑县| 肥东县| 榆社县| 海南省| 环江| 古丈县| 昌宁县| 长海县| 连云港市| 和平区| 丰县| 铜川市| 琼海市| 垫江县| 鄂托克旗| 合阳县| 德格县|