在Chrome扩展程序中拦截DNS请求? [英] Intercept DNS request in a Chrome Extension?

查看:515
本文介绍了在Chrome扩展程序中拦截DNS请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想测试 http://www.domain.com ,但是我想通过切换IP出(例如一个解析为127.0.0.1和另一个192.168.1.200)是否可以写/使用chrome扩展来处理拦截DNS查询并解决我的IP选择?



目前的解决方法是利用主机文件并刷新DNS缓存来在它们之间进行切换,但这不是最优的,希望浏览器扩展可以处理同样的事情。

解决方案

没有机制可以在Chrome内部本地操作DNS请求/响应,甚至不需要通过即将到来的WebRequest API。



<有没有理由需要用完全相同的域名进行测试?在 http://dev.example.com/ 上设置开发环境(或 http://example.dev/ ,如果您运行自己的DNS或编辑您的主机文件)是一个干净的机制,用于产生效果想要一种能够访问您的API的功能;写一个扩展,给你一个按钮,按一下按钮在两个域之间切换将是微不足道的


If I want to test http://www.domain.com, but I want to test two versions of it by switching the IP out (e.g. one resolves to 127.0.0.1 and the other 192.168.1.200) is it possible to write/use a chrome extension to handle intercepting the DNS query and resolving to my IP of choice?

The current workaround is to utilize the hosts file and flush the DNS cache to switch between them but that's less than optimal and was hoping a browser extension could handle the same thing.

解决方案

There's no mechanism to manipulate DNS requests/responses natively inside Chrome, not even via the upcoming WebRequest API.

Is there a reason that you need to test with exactly the same domain name? Setting up a dev environment on something like http://dev.example.com/ (or http://example.dev/ if you run your own DNS or have edited your hosts file) is a clean mechanism for producing the effect you want in a way that's functional with the APIs you have access to; writing an extension that gave you a button to toggle between the two domains with the push of a button would be trivial

这篇关于在Chrome扩展程序中拦截DNS请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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