需求:
我要查询百度域名的到期时间或者开始时间
思路分析:
如果在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
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金钱帮资源网 Copyright www.kbjia.com
暂无“python 获取域名到期时间的方法步骤”评论...
更新日志
2024年10月07日
2024年10月07日
- 班得瑞原装进口《第二张新世纪专辑:寂静山林》1CD[APE/CUE分轨][327.1MB]
- Beyond.1989-真的见证(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 陈怡婷.2024-予你的心谁来赔【福茂】【FLAC分轨】
- 陈冠希.2003-HITS.OR.MISSES【英皇娱乐】【WAV+CUE】
- 班得瑞原装进口《第三张新世纪专辑:春野》1CD[APE/CUE分轨][278.9MB]
- 班得瑞原装进口《第四张新世纪专辑:蓝色天际》1CD[APE/CUE分轨][284.8MB]
- 班得瑞原装进口《第五张新世纪专辑:迷雾森林+EP》1CD[APE/CUE分轨][334.2MB]
- 田震.1997-顺其自然(日版)【红星生产社】【WAV+CUE】
- 小虫.1996-想得太美【滚石】【WAV+CUE】
- 谢采妘.2016-邓丽君名曲专辑【丰荣】【WAV+CUE】
- 张含韵.2007-一人一梦【天中文化】【WAV+CUE】
- 蟑螂乐队.1999-帮个忙【福茂】【WAV+CUE】
- 张宇.2001-替身【EMI百代】【WAV+CUE】
- 班得瑞原装进口《第六张新世纪专辑:日光海岸》1CD[APE/CUE分轨][339.5MB]
- 班得瑞原装进口《第七张新世纪专辑:梦花园》1CD[APE/CUE分轨][331.4MB]