黑松山资源网 Design By www.paidiu.com
需求:
我要查询百度域名的到期时间或者开始时间
思路分析:
如果在linux系统中直接使用下面命令即可:
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执行不成功,所以只能换成通过shell脚本去执行。
init_sh函数检查shell脚本不存在则创建,这样不需要多写一个脚本,有程序生成。
#!/usr/bin/python # -*- coding: utf-8 -*- # author: chentufeng # create time: 2020 12 25 import commands,os script_sh = ".tmp.sh" # 自动生成shell脚本用来执行shell命令获取时间 def init_sh(): if not os.path.exists(script_sh): with open(script_sh, 'w') as file_object: file_object.write("yuming=$1\ntag=$2\n" "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__': #初始化函数 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
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年07月03日
2024年07月03日
- 华语流行S.H.E《12CD》2001~2010[APE+CUE][3.7GB]
- 北风之望饮品怎么调配?饮品调酒配方分享
- 原画壁纸及美图第254期,无水印可自取
- 原画壁纸及美图第255期,无水印可自取
- 群星.1991-宝丽金冬日浓情【宝丽金】【WAV+CUE】
- 胡杨林.2006-香水有毒【太格印象】【WAV+CUE】
- 陈晓东.2002-从未忘记2CD【环球】【WAV+CUE】
- 绝区零珂蕾妲阵容怎么搭配好 珂蕾妲队伍搭配攻略
- 绝区零暴击鸣徽有哪些 绝区零暴击鸣徽效果介绍
- 魔兽世界奥格瑞玛法师训练师在哪 奥格瑞玛法师训练师位置介绍
- 《艾尔登法环》dlc带电祷告位置介绍
- 《幻兽帕鲁》泰锋boss坐标位置介绍
- 《山河旅探》6月份更新内容介绍
- 群星.2012《高雄国际Hi-End音响大展纪念发烧金碟(最响宣言)》[WAV分轨].
- 黄宣2021-Beanstalk[否极泰来][WAV+CUE]