"' 192.168.0.1 --> www.xxx.com 192.168.0.2 192.168.0.3 Gets the business domain A record, queries out all IP address lists, and requests the monitoring page in Get mode using the request () method of the Httplib module. Monitor business All service IP is service OK "' #! /usr/bin/env pythonimport dns.resolverimport osimport http.clientimport socketiplist= [] #定义ip列表变量appdomain = "51cto.com" #定义业务域名 (example) def get_iplist (domain= ""): #域名解析函数, IP is appended to iplist try: a= after parsing succeeds Dns.resolver.query (Domain, ' A ') except Exception as e: print ("Dns resolver error:" +str (e)) return for i in A.response.answer: for&nbsP;j in i.items: iplist.append (j.address) return truedef checkip (IP): checkurl=ip + ": getcontent=" #socket. Setdefaulttimeout (5) #使用socet模块定义超时时间为5秒 http.client.socket.setdefaulttimeout (5) conn=http.client.httpconnection (checkurl) #创建http链接对象 try: conn.request ("GET", "/", headers={"host": AppDomain}) #发起URL请求, adding host hosts T-header r=conn.getresponse () getcontent=r.read #获取URL页面前1个字符 for availability check finally: if getcontent== "<!doctype html>": #监控URL页的内容一般事先定义好的, such as "HTTP200", etc. &Nbsp; print (ip+ "[OK]") else: print (ip+ "[ERROR]") # Here can be placed warning program, can be mail, can be SMS if __name__== "__main__": if get_iplist (AppDomain) And len (IPList) > 0 : #条件: Domain name resolution returns at least one ip for ip in iplist: Checkip (IP) else: print ("DNS Resolver error. ")
DNS domain name round-robin business monitoring