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

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

 更新時(shí)間:2023年11月03日 15:05:47   作者:yunson_Liu  
這篇文章主要介紹了python腳本監(jiān)聽域名證書過期時(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)聽域名證書過期時(shí)間,并將通知消息到釘釘?shù)奈恼戮徒榻B到這了,更多相關(guān)python域名證書過期時(shí)間內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

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

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

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

    Python加密word文檔詳解

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

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

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

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

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

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

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

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

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

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

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

    如何建立一個(gè)超圖詳解

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

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

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

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

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

最新評(píng)論

奈曼旗| 遂昌县| 城步| 曲阳县| 平度市| 剑川县| 伊金霍洛旗| 乌拉特前旗| 偃师市| 自治县| 汤原县| 留坝县| 同德县| 颍上县| 星子县| 卓尼县| 思茅市| 商洛市| 新巴尔虎左旗| 武定县| 辉县市| 漳州市| 广平县| 文昌市| 项城市| 辉县市| 西林县| 达日县| 阳山县| 乐至县| 宁河县| 攀枝花市| 仙居县| 阳信县| 探索| 霞浦县| 怀柔区| 台江县| 日土县| 信丰县| 湛江市|