默认情况下,Twisted在连接到Linux系统上的网站时会读取/etc/hosts
。我只是想知道哪个扭曲文件选择/etc/hosts
,所以我可以进入并将其更改为我选择的文件?
答案 0 :(得分:2)
您正在寻找的代码位于Resolver Object line 621。如果要更改您在所需主机文件中传递的解析程序的行为,如下所示。
from twisted.names import client
from twisted.internet import reactor
def do_lookup(domain):
hosts = "/tmp/example"
resolver = client.createResolver(servers=None, resolvconf=None, hosts="/tmp/example")
d = resolver.getHostByName(domain)
d.addBoth(lookup_done)
def lookup_done(result):
print(result)
reactor.stop()
domain = b'twistfoo.com'
reactor.callLater(0, do_lookup, domain)
reactor.run()