DNS就是一个数据服务器,里面都保存这类似的文件,比如www.123.com=192.168.1.1
然后你在地址栏访问www.123.com的时候,把请求发送到DNS服务器,要求查询对应的地址地址,然后结果是192.168.1.1,再然后就打开那个网站了,hehe,我行的形容很白痴,不过基本上就是这个原理~
import sysimport socket
import dns.resolver
print 'Argument List:', str(sys.argv)
site = sys.argv[1]
dns_server = sys.argv[2]
# Basic CNAME query the host's DNS
for rdata in dns.resolver.query(site, 'CNAME') :
print rdata.target
# Basic A query the host's DNS
for rdata in dns.resolver.query(site, 'A') :
print rdata.address
###下边是制定dns解析的服务器设置
# Setting an specific DNS Server
resolver = dns.resolver.Resolver()
resolver.nameservers = [socket.gethostbyname(dns_server)]
# Basic CNAME query with the specific DNS server
answer = resolver.query(site, 'CNAME')
for rdata in answer :
print rdata.target
# Basic A query with the specific DNS server
answer = resolver.query(site, 'A')
for rdata in answer :
print rdata.address
To run:(命令执行)
python dnsdig.py www.youtube.com 8.8.8.8
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)