#!/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
本文转自hahazhu0634 51CTO博客,原文链接:http://blog.51cto.com/5ydycm/1620378,如需转载请自行联系原作者