码迷,mamicode.com
首页 > 其他好文 > 详细

域名ip查看

时间:2015-03-14 20:09:08      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:域名 ip

#!/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查看

标签:域名 ip

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!