gpt4 book ai didi

python - 扭曲的dns不起作用

转载 作者:太空狗 更新时间:2023-10-30 02:06:21 25 4
gpt4 key购买 nike

我想知道为什么以下内容不起作用。

from twisted internet import defer, reactor
from twisted.python.failure import Failure
import twisted.names.client

def do_lookup(do_lookup):
d = twisted.names.client.getHostByName(domain)
d.addBoth(lookup_done)

def lookup_done(result):
print 'result:', result
reactor.stop()

domain = 'twistedmatrix.com'
reactor.callLater(0, do_lookup, domain)
reactor.run()

结果:

result: [Failure instance: Traceback
(failure with no frames): <class
'twisted.names.error.ResolverError'>:
Stuck at response without answers or
delegation ]

最佳答案

在撰写本文时,这在 Windows 上失败了,因为它使用了无效的 Windows 主机文件路径(在 twisted.names.client.createResolver 中。它使用“c:\windows\hosts”。这对 Windows 版本 98 和 Me 很好(引用 here ),但如果使用像 XP 这样“现代”的版本,则会失败。

今天,它可能应该使用类似的东西:

hosts = os.path.join(
os.environ.get('systemroot','C:\\Windows'),
r'system32\drivers\etc\hosts'
)

认为虽然这只能部分解决问题(或者这可能是转移注意力)。

这仅适用于在该主机文件中实际指定的名称。它可能需要做的是对 DNS 服务器进行某种注册表查询,然后查询它以进行实际的 DNS 名称查找。

This 配方看起来很有希望获得实际的 DNS 服务器。

关于python - 扭曲的dns不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4065551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com