Python,为基于套接字的应用程序实现代理支持(不是 urllib2)

发布于 2024-08-29 00:50:59 字数 238 浏览 3 评论 0原文

我有点困惑:我有一个简单的信使客户端程序(纯Python,套接字),我想添加代理支持(http/s,socks),但是我对如何去做有点困惑。我假设套接字级别的连接将完成到代理服务器,此时标头应包含 CONNECT + 目标 IP(聊天服务器的)和身份验证(如果代理需要如此),但是其余的就是有点超出我的范围了。如何处理后续连接,特别是读/写等...

是否有关于 Python 中基于套接字(tcp)编程的代理支持实现的指南?

谢谢

I am little stumped: I have a simple messenger client program (pure python, sockets), and I wanted to add proxy support (http/s, socks), however I am a little confused on how to go about it. I am assuming that the connection on the socket level will be done to the proxy server, at which point the headers should contain a CONNECT + destination IP (of the chat server) and authentication, (if proxy requires so), however the rest is a little beyond me. How is the subsequent connection handled, specifically the reading/writing, etc...

Are there any guides on proxy support implementation for socket based (tcp) programming in Python?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魔法唧唧 2024-09-05 00:50:59

也许使用类似 SocksiPy 的东西,它会为您完成所有协议详细信息,并让您通过 SOCKS 代理进行连接没有它你会吗?

Maybe use something like SocksiPy which does all the protocol details for you and would let you connect through a SOCKS proxy as you would without it?

孤者何惧 2024-09-05 00:50:59

这非常简单 - 发送 HTTP 请求后: CONNECT example.com:1234 HTTP/1.0\r\nHost: example.com:1234\r\n\r\n\r\n,服务器响应 HTTP/1.0 200 Connectionbuilt\r\n\r\n 然后(双行结束后)您可以像在没有代理的情况下与 example.com 端口 1234 进行通信一样进行通信(据我所知,您已经完成了客​​户端-服务器通信部分)。

It is pretty simple - after you send the HTTP request: CONNECT example.com:1234 HTTP/1.0\r\nHost: example.com:1234\r\n<additional headers incl. authentication>\r\n\r\n, the server responds with HTTP/1.0 200 Connection established\r\n\r\n and then (after the double line ends) you can communicate just as you would communicate with example.com port 1234 without the proxy (as I understand you already have the client-server communication part done).

︶葆Ⅱㄣ 2024-09-05 00:50:59

看看 stunnel

Stunnel 可以让您安全
非 SSL 感知守护进程和协议
(如 POP、IMAP、LDAP 等)
Stunnel提供加密,
不需要对守护进程进行任何更改
代码

Have a look at stunnel.

Stunnel can allow you to secure
non-SSL aware daemons and protocols
(like POP, IMAP, LDAP, etc) by having
Stunnel provide the encryption,
requiring no changes to the daemon's
code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文