Python DNS domain name polling business monitoring

Source: Internet
Author: User

Read the Book of the Great God, I hereby do the study notes, the realization of a slightly different way is python3.5

Most DNS parsing is a domain name that corresponds to an IP address, but DNS polling enables a domain name to correspond to multiple IPs for the simplest and most efficient load balancing.

1, implementation steps

1) To achieve the resolution of the domain name, get the domain name of all A records resolution IP list

2) HTTP-level probing of IP list

2, Code

#!/usr/local/bin/python3.5#-*-coding:utf-8-*-ImportDns.resolverImporthttplib2iplist=[]appdomain="www.a.com"defGet_iplist (domain=""):    Try: A= Dns.resolver.query (Domain,"A")    exceptException as E:Print("DNS Resolver error:"+str (e))return     forIinchA.response.answer: forJinchi.items:iplist.append (j.address)returnTruedefcheckip (IP): Checkurl='/ http'+ IP +":"getcontent=""Httplib2.socket.setdefaulttimeout (5) Conn=Httplib2. Http ()Try: Resp,getcontent=conn.request (Checkurl)finally:        ifresp['Status']==" $":            Print(ip+"[OK]")        Else:            Print(ip+"[Error]")if __name__=="__main__":    ifGet_iplist (AppDomain) andLen (IPList) >0: forIpinchiplist:checkip (IP)

Results

end!

Python DNS domain name polling 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.