国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python 獲取域名到期時(shí)間的方法步驟

瀏覽:2日期:2022-06-28 08:16:52
需求:

我要查詢百度域名的到期時(shí)間或者開始時(shí)間

思路分析:

如果在linux系統(tǒng)中直接使用下面命令即可:

echo | openssl s_client -servername www.baidu.com -connect www.baidu.com:443 2>/dev/null | openssl x509 -noout -dates|egrep ‘notAfter’|awk -F’=|GMT’ ‘{print $2}’

但是這個(gè)命令使用python2 的commands執(zhí)行不成功,所以只能換成通過shell腳本去執(zhí)行。

init_sh函數(shù)檢查shell腳本不存在則創(chuàng)建,這樣不需要多寫一個(gè)腳本,有程序生成。

#!/usr/bin/python# -*- coding: utf-8 -*-# author: chentufeng# create time: 2020 12 25import commands,osscript_sh = '.tmp.sh'# 自動(dòng)生成shell腳本用來(lái)執(zhí)行shell命令獲取時(shí)間def init_sh(): if not os.path.exists(script_sh): with open(script_sh, ’w’) as file_object: file_object.write('yuming=$1ntag=$2n' 'ymtime=`echo | openssl s_client -servername $yuming -connect $yuming:443 2>/dev/null | openssl x509 -noout -dates|egrep '$tag'|awk -F’=|GMT’ ’{print $2}’`n' #時(shí)間轉(zhuǎn)換,如果需要也可以轉(zhuǎn)換成其他格式 'date -d '$ymtime' ’+%Y-%m-%d %H:%M:%S’n')if __name__ == ’__main__’: #初始化函數(shù) init_sh() yuming = 'www.baidu.com' tag = 'notBefore' #notBefore 開始時(shí)間;notAfter 到期時(shí)間 cmd = 'sh %s %s %s'%(script_sh, yuming, tag) restatus,retime = commands.getstatusoutput(cmd) print('獲取的時(shí)間:%s'%retime)

輸出結(jié)果:

到期時(shí)間[root@測(cè)試機(jī) ~]# python aa.py獲取的時(shí)間:2021-07-26 05:31:02開始時(shí)間[root@測(cè)試機(jī) ~]# python aa.py獲取的時(shí)間:2020-04-02 07:04:58

到此這篇關(guān)于python 獲取域名到期時(shí)間的方法步驟的文章就介紹到這了,更多相關(guān)python 獲取域名到期時(shí)間內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 隆子县| 介休市| 临夏县| 奉贤区| 通州市| 和硕县| 师宗县| 孟州市| 平罗县| 祁门县| 永寿县| 惠安县| 襄城县| 芦溪县| 通江县| 黄梅县| 镇原县| 巴林左旗| 兴隆县| 通道| 洪洞县| 抚远县| 邻水| 宁都县| 遂平县| 二连浩特市| 万宁市| 册亨县| 新昌县| 淮阳县| 湖北省| 从江县| 无为县| 义乌市| 铁岭县| 察隅县| 青海省| 友谊县| 香港 | 巴林右旗| 两当县|