Python定期查询域名状态并完成记录的小脚本,python域名,对于一个站长来说,手里有
Python定期查询域名状态并完成记录的小脚本,python域名,对于一个站长来说,手里有
对于一个站长来说,手里有几个或十几个域名都是很正常的事情,想要及时统计这些域名的相关信息却是很费心费力的。一但忘记,可能就会错失一个好的网站。那如何来避免这样的问题发生呢?我利用目前正在学习的python语言完成了一个,关于Python定期查询域名状态并完成记录的小脚本。贴出源代码来和大家一起分享下。
import osimport timeimport sysdef _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]==';':continuea.insert(len(i),str(i))a.insert(len(a),"-------------------------------------------------------------\n")f.close()if len(a) == 3:return 0else:return adef _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 bfor i in b[:]:if i[0]==';':continuea.insert(len(a),i)a.insert(len(a),"-------------------------------------------------------------\n")f.close()if len(a) == 3:return 0else:return a#www.iplaypy.comdef _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 adef _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 numns_ok=0ns_err=0 #init a_ok numa_ok=0a_err=0os.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()
编橙之家文章,
相关内容
- Python完成远程登陆RouterOS执行并返回命令的操作,pyth
- python编写ini文件的方法,,from ConfigP
- python方法筛选特定宽度的图片方法,,记得之前在做图片
- 完成自动生成CMake脚本的python方法,cmakepython,下面一段
- python对比并输出多文件夹内的不同文件,python对比,py
- Python批量下载人人网相册图片的实现,,Python批量下载人
- 关于webpy中form radio单选框的bug修复,webpyradio,这是我在
- Python完成抓取并写入mysql库的方法,python抓取mysql库,P
- python求公约数和公倍数的方法源码,python公约数,Pytho
- 模拟经营的python小游戏,python小游戏,用Python写的小游戏
评论关闭