使用 dns.resolver (pythondns) 设置特定的 DNS 服务器 [英] Set specific DNS server using dns.resolver (pythondns)

查看:108
本文介绍了使用 dns.resolver (pythondns) 设置特定的 DNS 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 dnspython 中的 dns.resolver.

I am using dns.resolver from dnspython.

是否可以设置用于查询的服务器 IP 地址?

Is it possible to set the IP address of the server to use for queries ?

推荐答案

虽然这有点老话题,但我会加入.我遇到了同样的挑战,我想我会分享解决方案.因此,基本上配置文件将填充您正在使用的 dns.resolver.Resolver 的nameservers"实例变量.因此,如果你想强制你的解析器使用一个特定的名称服务器,你可以直接这样做:

Although this is somewhat of an old thread, I will jump in. I've bumped against the same challenge and I thought I would share the solution. So, basically the config file would populate the 'nameservers' instance variable of the dns.resolver.Resolver you are using. Hence, if you want to coerce your Resolver to use a particular nameserver, you can do it direcly like this:

import dns.resolver

my_resolver = dns.resolver.Resolver()

# 8.8.8.8 is Google's public DNS server
my_resolver.nameservers = ['8.8.8.8']

answer = my_resolver.query('google.com')

希望有人觉得它有用.

这篇关于使用 dns.resolver (pythondns) 设置特定的 DNS 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆