DNS module Dnspython application and Business monitoring example

Source: Internet
Author: User
Tags cname record example mx record


1 Dnspython Processing module installation, source mode

wget http://www.dnspython.org/kits/1.9.4/dnspython-1.9.4.tar.gz

Tar zxf dnspython-1.9.4.tar.gz

CD dnspython-1.9.4/

Python setup.py Install


2 parsing examples

A record query example

#!/usr/bin/env python#-*-coding:utf-8-*-import dns.resolverdomain = raw_input ("Please enter a domain name to resolve:") A = Dns.resolver.query (Domain, ' A ') for I in A.response.answer:for j in i.items:if J.rdtype = = 1:print j.address

MX Record Example

#!/usr/bin/env python#-*-coding:utf-8-*-import dns.resolverdomain=raw_input (' Please enter a domain name: ') mx=dns.resolver.query ( Domain, ' MX ') for I in Mx:print i.preference, I.exchange

NS Record Example

Import dns.resolverdomain=raw_input (' Please enter a domain name: ') ns=dns.resolver.query (domain, ' NS ') for I in NS.response.answer:for J In I.items:print J.to_text ()

CNAME record Example

Import dns.resolverdomain=raw_input (' Please enter a domain name: ') cname=dns.resolver.query (domain, ' cname ') for I in Cname.response.answer:for J in I.items:print J.to_text ()


3 Monitoring your business with DNS domain name rotation

monitoring example

#!/usr/bin/env python# -*- coding: utf-8 -*-import dns.resolverimport  Osimport httplibiplist=[]appdomain= "www.ctrip.com" Def get_iplist (domain= ""):         try:            a= Dns.resolver.query (Domain, ' A ')         except Exception,e:             print  "Dns resolver error:" + STR (e)         for i in A.response.answer:             for j in i.items:                 if j.rdtype == 1:                      iplist.append (j.adDress)         return truedef checkip (IP):         checkurl=ip+ ":"         getcontent= ""         httplib.socket.setdefaulttimeout (5)          conn=httplib. Httpconnection (Checkurl)         try:                 conn.request ("GET", "/", headers={"Host": AppDomain})                 r= Conn.getresponse ()                  getcontent=r.read (        finally:    )         print getcontent             if getcontent== "<! Doctype html> ":                     print ip+ ": 80 port normal   [ok]"              else:                     print ip+ ": 80 port Exception   [error]" if  __name__== "__main__":     if get_iplist (AppDomain)  and len (IPList) >0:             for ip in iplist:                      checkip (IP)     else:             print  "Dns resolver error"

Execute Python test1.py

<! DOCTYPE html>

118.89.206.133:80 Port OK [OK]





DNS module Dnspython application and Business monitoring example

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.