python 獲取域名到期時間的方法步驟
我要查詢百度域名的到期時間或者開始時間
思路分析:如果在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}’
但是這個命令使用python2 的commands執(zhí)行不成功,所以只能換成通過shell腳本去執(zhí)行。
init_sh函數(shù)檢查shell腳本不存在則創(chuàng)建,這樣不需要多寫一個腳本,有程序生成。
#!/usr/bin/python# -*- coding: utf-8 -*-# author: chentufeng# create time: 2020 12 25import commands,osscript_sh = '.tmp.sh'# 自動生成shell腳本用來執(zhí)行shell命令獲取時間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' #時間轉換,如果需要也可以轉換成其他格式 'date -d '$ymtime' ’+%Y-%m-%d %H:%M:%S’n')if __name__ == ’__main__’: #初始化函數(shù) init_sh() yuming = 'www.baidu.com' tag = 'notBefore' #notBefore 開始時間;notAfter 到期時間 cmd = 'sh %s %s %s'%(script_sh, yuming, tag) restatus,retime = commands.getstatusoutput(cmd) print('獲取的時間:%s'%retime)
輸出結果:
到期時間[root@測試機 ~]# python aa.py獲取的時間:2021-07-26 05:31:02開始時間[root@測試機 ~]# python aa.py獲取的時間:2020-04-02 07:04:58
到此這篇關于python 獲取域名到期時間的方法步驟的文章就介紹到這了,更多相關python 獲取域名到期時間內容請搜索好吧啦網以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. HTTP協(xié)議常用的請求頭和響應頭響應詳解說明(學習)2. IntelliJ IDEA創(chuàng)建web項目的方法3. Django如何繼承AbstractUser擴展字段4. Python寫捕魚達人的游戲實現(xiàn)5. 存儲于xml中需要的HTML轉義代碼6. Android studio 解決logcat無過濾工具欄的操作7. Django REST Swagger實現(xiàn)指定api參數(shù)8. ASP.NET MVC通過勾選checkbox更改select的內容9. ASP中實現(xiàn)字符部位類似.NET里String對象的PadLeft和PadRight函數(shù)10. django創(chuàng)建css文件夾的具體方法
