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