是否可以在 Firefox 中添加和修改 dns 缓存条目?
我正在尝试完成一些特定的测试要求。
现在的需求之一是将一些不存在的url重定向到特定的ip,这就是dns正在做的事情。我认为 Firefox 使用内部 dns 缓存。但我找不到可以用来更改此类 dns 缓存的合适服务。另一方面,我不知道 Firefox 是否支持某种服务来自定义 dns 过程,我的意思是提供自定义结果而不是真正从 DNS 服务器获取结果。
由于我需要启动许多 Firefox 进程来同时完成工作,所以我不能简单地通过更改系统主机文件来做到这一点,因为它会影响其他进程。
有什么想法吗?
I am trying to accomplish some specific test requirement.
One of the requirement now is to redirect some nonexistent url to specific ip, which is what the dns is doing. I think firefox is using internal dns cache. But I cannot find a proper service that I can use to change such kind of dns cache. On the other hand, i have no idea if firefox support some kind of service to customize the dns process, I mean give a customized result instead of really getting from DNS Server.
As I need to start many firefox process to do the work concurrently, so I cannot do this simply by changing the system hosts file, cause it will affect other process.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,在 Firefox 中无法修改 DNS 响应,DNS 服务仅允许触发 DNS 请求。您可以做的是识别
NS_ERROR_UNKNOWN_HOST
响应并以某种方式将其重定向到您的服务器。虽然识别并不是特别困难,但重定向却很复杂。您可以添加进度侦听器并检查请求是否在onStateChange 方法(
if (aFlag & STATE_STOP)
)。参数aStatus
为您提供请求的状态,您将查找状态Components.results.NS_ERROR_UNKNOWN_HOST
。对于顶级请求 (aFlag & STATE_WINDOW
),您可以更改窗口位置以向不同的服务器发出请求。对于其他请求 - 不知道如何“重定向”那里。No, modifying DNS responses isn't possible in Firefox, the DNS service merely allows triggering a DNS request. What you could do is recognizing
NS_ERROR_UNKNOWN_HOST
response and somehow redirecting it to your server. While recognizing isn't particularly hard, redirecting is complicated. You could add a progress listener and check whether a request finished inonStateChange
method (if (aFlag & STATE_STOP)
). The parameteraStatus
gives you the status of the request, you would be looking for statusComponents.results.NS_ERROR_UNKNOWN_HOST
. And for top-level requests (aFlag & STATE_WINDOW
) you could change window location to make a request to a different server instead. For other requests - don't know how one would "redirect" there.