#!/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
原文:http://5ydycm.blog.51cto.com/115934/1620378