python 获取域名到期时间的方法步骤
需求:
我要查询百度域名的到期时间或者开始时间
思路分析:
如果在linux系统中直接使用下面命令即可:
echo|openssls_client-servernamewww.baidu.com-connectwww.baidu.com:4432>/dev/null|opensslx509-noout-dates|egrep‘notAfter'|awk-F'=|GMT'‘{print$2}'
但是这个命令使用python2的commands执行不成功,所以只能换成通过shell脚本去执行。
init_sh函数检查shell脚本不存在则创建,这样不需要多写一个脚本,有程序生成。
#!/usr/bin/python #-*-coding:utf-8-*- #author:chentufeng #createtime:20201225 importcommands,os script_sh=".tmp.sh" #自动生成shell脚本用来执行shell命令获取时间 definit_sh(): ifnotos.path.exists(script_sh): withopen(script_sh,'w')asfile_object: file_object.write("yuming=$1\ntag=$2\n" "ymtime=`echo|openssls_client-servername$yuming-connect$yuming:4432>/dev/null|opensslx509-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@测试机~]#pythonaa.py
获取的时间:2021-07-2605:31:02
开始时间
[root@测试机~]#pythonaa.py
获取的时间:2020-04-0207:04:58
到此这篇关于python获取域名到期时间的方法步骤的文章就介绍到这了,更多相关python获取域名到期时间内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。