DNS domain name round-robin business monitoring

Source: Internet
Author: User

"'                 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.