首页 > 其他 > 详细

域名ip查看

时间:2015-03-14 20:07:52      阅读:265      评论:0      收藏:0      [点我收藏+]

#!/usr/bin/env python
#Edit By zhuzhengjun
#query domain ip

import dns.resolver

domain_file=open(‘domain_list.txt‘,‘r‘)
domains=[]

for domain in domain_file:
    domains.append(domain.strip())

def get_iplist(domain=""):
    try:
        A = dns.resolver.query(domain, ‘A‘)
    except Exception,e:
        print domain," ","Resolver A Exception"
        return
    for i in A.response.answer:
        for j in i.items:
            print j.address
    print "-"*20

def get_cname(domain=""):
    try:
        cname = dns.resolver.query(domain, ‘CNAME‘)
    except Exception,e:
        print domain," ","Resolver CNAME Exception"
        return
    for i in cname.response.answer:
        for j in i.items:
            try:
                get_iplist(j.to_text())
            except AttributeError,e:
                get_cname(j.to_text())

for domain in domains:
    print "%s" %domain
    try:
        get_iplist(domain)
    except AttributeError,e:
        try:
            get_cname(domain)
        except AttributeError,e:
            print "Error"

提供一份域名列表,便会打印出对应的ip

域名ip查看

原文:http://5ydycm.blog.51cto.com/115934/1620378

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!