简体   繁体   English

Python-如何创建代理隧道

[英]Python - How to create a tunnel of proxies

I asked this question: Wrap packets in connect requests until reach the last proxy 我问了这个问题: 将数据包包装在连接请求中,直到到达最后一个代理为止

And I learnt that to create a chains of proxies I have to: 我了解到要创建代理链,我必须:

  • create a socket 创建一个套接字
  • connect the socket to proxy A 将套接字连接到代理A
  • create a tunnel via A to proxy B - either with HTTP or SOCKS protocol similar 通过A创建到代理B的隧道-使用HTTP或SOCKS协议
  • create a tunnel via [A,B] to proxy C similar 通过[A,B]创建隧道以代理C
  • create a tunnel via [A,B,C] to D 通过[A,B,C]到D创建一条隧道
  • ... until your last proxy is instructed to built the tunnel to the ...直到指示您的最后一个代理建立通向
    final target T 最终目标T

I got what I have to do until the second point, cause I think I just have to add the "CONNECT" header to the http request to the proxy A. But my question is, in this example http request: 在第二点之前,我必须要做的事情,因为我想我只需要向代理A的http请求中添加“ CONNECT”标头即可。但是我的问题是,在此示例http请求中:

CONNECT ipproxy:80 HTTP/1.1
Host: ?:80

In the host header I should put again the proxy ip or something else? 在主机标头中,我应该再次放置代理ip或其他内容? Like the proxy B ip or the final site domain? 像代理B ip还是最终站点域?

Also, I didn't understand how to go on from the third point to the next... because I don't know how to tell the proxy A to create a tunnel to proxyB and then proxy B to create a tunnel to proxy C that goes to the final site.. 另外,我不知道如何从第三点继续到下一个……因为我不知道如何告诉代理A创建到proxyB的隧道,然后告诉代理B创建到C的隧道。转到最终站点。

Examples of how can I do it with python? 我如何使用python的示例? Or some doc? 还是一些文档?

There is no Host header with CONNECT. CONNECT没有主机头。 Ie to request HTTP proxy A to create a tunnel to HTTP proxy B you just use: 即请求HTTP代理A创建到HTTP代理B的隧道,您只需使用:

>>> CONNECT B_host:B_port HTTP/1.0
>>>
<<< 200 connections established
<<<

And then you have this tunnel to proxy B via proxy A. Inside this tunnel you then can create another tunnel to target T, ie on the same socket send and receive next: 然后,您具有通过代理A到达代理B的隧道。在该隧道内,您可以创建另一个到目标T的隧道,即在同一套接字上发送和接收下一条消息:

>>> CONNECT T_host:T_port HTTP/1.0
>>>
<<< 200 connections established
<<<

Note that not all proxies allow you to CONNECT to arbitrary hosts and ports and they might also not allow arbitrary protocols like a tunnel inside a tunnel but only selected protocols like HTTPS. 请注意,并非所有代理都允许您连接到任意主机和端口,它们也可能不允许任意协议(例如,隧道内的隧道),而仅允许选择的协议(例如HTTPS)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM