来自浏览器的Python拦截Web流量 [英] Python Intercept Web Traffic from Browser

查看:310
本文介绍了来自浏览器的Python拦截Web流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python创建一个简单的Web过滤应用程序.我要执行的方法是监视tcp 80/443(http)端口上的流量,如果有流量,我想在让它通过之前检查一下.如果未通过检查,我希望将用户重定向到我选择的页面.

I'm trying to create a simple web filtering app in python. The way I want to do this is to monitor traffic on ports tcp 80/443 (http) and if there is traffic, I want to check something before I let it go through. If it fails the check, I would like for the user to be redirected to a page of my choosing.

所以我的问题是,当用户在浏览器中访问 http://www.google.com 时,有没有办法我可以拦截该请求,有没有办法我可以根据自己的选择将其重定向到另一个页面?

So my question is, when the user visits http://www.google.com in the browser, is there a way that I can intercept that request, and is there a way I can redirect them to another page by my choosing?

推荐答案

您需要编写一个Web代理,并将您的Web客户端代理服务器设置为

You need to write a web proxy, and set your web clients proxy server to http://localhost:8000/ (or whatever the proxy is listening on).

您的Web客户端随后将像这样发送HTTP:

Your web client will then send HTTP like this:

获取 http://www.google.com

到您的代理,然后必须将其重写为:

to your proxy which it must then rewrite as:

获取/

并发送到www.google.com,获取响应,然后将其通过原始套接字发送回客户端.请注意,解释已大大简化.

and send on to www.google.com, getting the response and then sending it back on the original socket to the client. Note that explanation is massively simplified.

无论如何,它是所有标准的东西,我怀疑Python Web代理已经存在供您入侵.

Anyway, its all standard stuff and I suspect Python web proxies exist already for you to hack on.

http://proxies.xhaus.com/python/

这篇关于来自浏览器的Python拦截Web流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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