定期使用dig 查询域名的NS/A记录并做简单记录,digns,import osimp
文章由Byrx.net分享于2019-03-23 09:03:52
定期使用dig 查询域名的NS/A记录并做简单记录,digns,import osimp
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]==';': continue a.insert(len(i),str(i)) a.insert(len(a),"-------------------------------------------------------------\\n") f.close() if len(a) == 3: return 0 else: 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 www.cindamc.com.cn | grep www.cindamc.com.cn >/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 adef _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 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()#该片段来自于http://byrx.net
评论关闭