Python定期查询域名状态并完成记录的小脚本
对于一个站长来说,手里有几个或十几个域名都是很正常的事情,想要及时统计这些域名的相关信息却是很费心费力的。一但忘记,可能就会错失一个好的网站。那如何来避免这样的问题发生呢?我利用目前正在学习的python语言完成了一个,关于Python定期查询域名状态并完成记录的小脚本。贴出源代码来和大家一起分享下。
import os import time import sys def _nscheck(): a=[] a.insert(0,"--------------------------------------------------------------\n") a.insert(len(a),"opertime: "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+'\n') os.system('dig @202.106.0.20 cindamc.com.cn -t ns | grep ns >/tmp/tmpcheck') f=open('/tmp/tmpcheck','r') b=f.readlines() for i in b[:]: if i[0]==';': continue a.insert(len(i),str(i)) a.insert(len(a),"-------------------------------------------------------------\n") f.close() if len(a) == 3: return 0 else: return a def _acheck(): a=[] a.insert(len(a),"-------------------------------------------------------------\n") a.insert(len(a),"opertime: "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+'\n') os.system('dig @202.106.0.20 #网址 | grep #网址 >/tmp/tmpcheck') f=open('/tmp/tmpcheck','r') b=f.readlines() #print b for i in b[:]: if i[0]==';': continue a.insert(len(a),i) a.insert(len(a),"-------------------------------------------------------------\n") f.close() if len(a) == 3: return 0 else: return a #www.iplaypy.com def _err(): a=[] a.insert(len(a),"-------------------------------------------------------------\n") a.insert(len(a),"opertime: "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+'\n') a.insert(len(a)," return result error!!!! \n") a.insert(len(a),"-------------------------------------------------------------\n") return a def _result(a_ok,a_err,ns_ok,ns_err): result=open('/home/dnscheck/result.txt','w') result.write('-----------------------------------------------------------------\n') result.write('project status conut\n') result.write(' A normal :'+str(a_ok)+' error :'+str(a_err)+' '+str(a_ok+a_err)+'\n') result.write(' NS normal :'+str(ns_ok)+' error :'+str(ns_err)+' '+str(ns_ok+ns_err)+'\n') result.write('-----------------------------------------------------------------\n') result.close() if __name__=='__main__': #init ns_ok num ns_ok=0 ns_err=0 #init a_ok num a_ok=0 a_err=0 os.system('rm -f /home/dnscheck/nscheck.txt') os.system('rm -f /home/dnscheck/acheck.txt') os.system('rm -f /home/dnscheck/result.txt') _ns = open('/home/dnscheck/nscheck.txt','a+') _a = open('/home/dnscheck/acheck.txt', 'a+') try: while 1: if _nscheck() == 0: ns_err+=1 _ns.writelines(_err()) _ns.flush() else: ns_ok+=1 _ns.writelines(_nscheck()) _ns.flush() if _acheck() == 0: a_err+=1 _a.writelines(_err()) _a.flush() else: a_ok+=1 _a.writelines(_acheck()) _a.flush() _result(a_ok,a_err,ns_ok,ns_err) time.sleep(60) except: _ns.close() _a.close() sys.exit()
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/code/scripts-shell/ss2494.html
相关文章 Recommend
- • 2019年3月最新消息: Python 3.4.10 现已推出
- • [上海]招Python量化系统开发工程师
- • 优集品网络科技有限公司招Python中/高级工程师
- • 爱因互动科技发展有限公司招募Python开发攻城狮
- • mozio招聘Python/Django工程师
- • Kavout金融科技公司招Python研发工程师
- • Python数组逆向输出,编程练习题实例四十
- • Python数组插入排序,编程练习题实例三十九
- • Python矩阵for循环应用,编程练习题实例三十八
- • Python操作Redis数据库方面的问题
- • 请python高手帮我看看这段python代码中函数setter的
- • Python什么方法可以快速将两个队列变成字典
我要分享到:
必知PYTHON教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
必知PYTHON模块 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • 绑定修改网卡绑定关系的python程序
- • 网友用python把IPv4地址变成LITNET-NAT64网段
- • 基于python Selenium的用户登录自动化测试
- • 用python代码科学上Google
- • python论坛自动签到用bs4模块
- • python北京地铁月支出简易计算器
- • 用python查找未注册的域名
- • Windows环境用Python备份MySQL脚本
- • 批量调整图片尺寸的python脚本
- • Python方法获取百度地图数据示例源码
图文精华 RECOMMEND
-
用python代码科学上Google
-
Windows环境用Python备份MySQL脚本
-
批量调整图片尺寸的python脚本
-
Python方法获取百度地图数据示例源
-
控制台进度自动刷新python方法源码
-
web.py能条件判断的页面执行计时方
热点文章 HOT
- web.py能条件判断的页面执行计时方法
- Windows环境用Python备份MySQL脚本
- 从糗事百科下载数据的python方法示例
- 基于python Selenium的用户登录自动化测试
- 解决Python2不支持datetime的json encode问题
- Python完成抓取并写入mysql库的方法
- 一个初学者练手的Python多线程实现下载的
- Python调chrome刷页面完成刷点击量操作