Skip to main content

Fast tcp/https/websocket/socks4/ssh tunnel serving as unified proxy server.

Project description

 _____            _          _____                        _
/__   \_   _ _ __| |__   ___/__   \_   _ _ __  _ __   ___| |
  / /\/ | | | '__| '_ \ / _ \ / /\/ | | | '_ \| '_ \ / _ \ |
 / /  | |_| | |  | |_) | (_) / /  | |_| | | | | | | |  __/ |
 \/    \__,_|_|  |_.__/ \___/\/    \__,_|_| |_|_| |_|\___|_|

PyPi version Unittest codecov.io

环境要求

  • 操作系统: WindowsLinuxMacOS
  • Python: >=3.5

主要功能

  • 提供访问各种不同代理服务的能力
  • 目前支持的代理服务类型包括:httpssocks4socks5websocketssh
  • 目前可以创建的代理服务类型有:httpssocks4socks5websocket
  • 还支持端口映射等非代理服务
  • 支持通过配置文件的方式,指定不同的策略,允许使用不同的代理服务访问不同的目标服务

安装方法

$ pip3 install turbo-tunnel

基本功能介绍

详情请见中文文档

端口映射

$ turbo-tunnel -l tcp://127.0.0.1:8080 -t tcp://www.qq.com:443

该命令可以将www.qq.com443端口到本地的8080端口。

$ turbo-tunnel -l tcp://127.0.0.1:8080 -t http://web-proxy.com:8080 -t tcp://www.qq.com:443

该命令会通过https类型的代理服务web-proxy.com:8080,将www.qq.com443端口到本地的8080端口。

如果不写127.0.0.1,则默认是0.0.0.0

创建代理服务

使用-l--listen参数,可以创建代理服务。

  • 创建 https 代理服务
$ turbo-tunnel -l http://username:password@:8080

usernamepassword是用于鉴权的用户名和密码,不指定则不对客户端鉴权;如果包含特殊字符需要进行urlencode

  • 创建 socks4 代理服务
$ turbo-tunnel -l socks4://userid@127.0.0.1:1080

socks4://也可以写成socks://,表示默认使用socks4协议。

userid参数用于鉴权,不指定则无需鉴权。

  • 创建 WebSocket 代理服务
$ turbo-tunnel -l ws://username:password@127.0.0.1/{addr}/{port}

{addr}{port}在这里是变量占位符,用于指示目标地址目标端口参数。这是因为WebSocket协议本身并不是一种代理协议,因此需要使用特定的字段来描述这些信息。运行过程中,当需要访问1.1.1.1:8888服务时,客户端会动态生成请求路径:/1.1.1.1/8888

这里可以根据自己的需要改成不同的格式,例如:/proxy-{addr}-{port}。但是,这里设置的格式需要与客户端指定的 url 格式一致。

目前没有提供wss协议,用户如果需要的话可以配合nginx搭建。

指定访问通道

通过-t--tunnel参数,可以指定访问目标服务器的通道,默认是直连。

  • 配置单个通道
$ turbo-tunnel -l http://127.0.0.1:8080 -t wss://username:password@proxy.com/{addr}/{port}

所有访问本地 https 代理服务的请求都会通过WebSocket代理服务进行转发。

这种方法可以用作代理协议格式的转换。

  • 配置多个通道
$ turbo-tunnel -l http://127.0.0.1:8080 -t socks://10.1.1.1:1080 -t ssh://username:password@10.2.2.2:22

配置多个通道时,会进行代理协议的嵌套,从而依次穿越所有通道,进行目标服务的访问。

设置全局透明代理

创建代理服务后,我们希望程序访问网络时能自动使用代理去访问。此时可以通过配置全局透明代理的方式来解决。

  • Windows & MacOS 可以安装Proxifier工具,该工具可以配置各种访问策略,访问不同服务时使用不同的代理服务器。

  • Liunx 可以使用proxychains工具,该工具类似于Proxifier,但是不能配置策略,而且需要在启动目标应用时在命令前增加proxychains前缀。

高级用法

使用配置文件

-c--config参数可以指定一个yaml格式的配置文件,可以配置服务参数访问策略。下面是一个配置文件的例子:

version: 1.0

listen: http://127.0.0.1:6666 # 配置监听地址

hosts:
  - domain: www.test.com
    ip: 1.2.3.4

tunnels:
  - id: direct
    url: tcp://
    default: true # 默认使用直连策略

  - id: block
    url: block:// # 禁止访问策略

  - id: web
    url: http://web-proxy.com:8080

  - id: private
    url: wss://test:mypassword@ws-proxy.com/proxy/{addr}/{port}
    dependency: web # 依赖web代理

rules:
  - id: local
    priority: 100 # 优先级,1-100,策略冲突时会选择优先级最高的策略
    addr: 127.0.0.1
    tunnel: direct

  - id: internal
    priority: 99
    addr: "192.168.*"
    port: 1-65535
    tunnel: direct

  - id: public
    priority: 90
    addr: "*"
    port: 80;443;8080
    tunnel: web # 访问外网使用web通道

  - id: private
    priority: 95
    addr: "*.private.com"
    port: 1-65535
    tunnel: private

  - id: test
    priority: 90
    addr: "*.baidu.com"
    port: 80;443
    tunnel: block # 不允许访问

扩展插件

turbo-tunnel 允许用户开发自己的插件,以支持新的代理服务或通道类型,还可以在运行过程中执行特殊操作,例如:动态修改收发的数据。

目前自带的插件有:

  • terminal: 展示运行过程中的连接情况
$ turbo-tunnel -l http://127.0.0.1:8080 -p terminal -p xxx

通过-p--plugin可以指定1-N个插件,插件加载顺序由启动命令行中-p参数的顺序决定。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turbo-tunnel-0.15.0.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

turbo_tunnel-0.15.0-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file turbo-tunnel-0.15.0.tar.gz.

File metadata

  • Download URL: turbo-tunnel-0.15.0.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for turbo-tunnel-0.15.0.tar.gz
Algorithm Hash digest
SHA256 d0b7b9a1c9c05fb9b82f32cce698ac3d8886e86c848a864b2c7a2dc53d11d61a
MD5 dadcbc39e5858babc3e3fe8b8efd1445
BLAKE2b-256 948a8e7370f098c0bd9f55cd69a5550e6e618ca37bafbbf6f338c3343b473c03

See more details on using hashes here.

File details

Details for the file turbo_tunnel-0.15.0-py3-none-any.whl.

File metadata

  • Download URL: turbo_tunnel-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for turbo_tunnel-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72ed36737914c82f8187c5713d550bed7a1ceb32c76afbc1d71fdf701ce74da3
MD5 9545462aa77a4f0f2268bed58fc61997
BLAKE2b-256 646f81c9ec0acbf60b044820653d3fe24bbd64c2e7248df73557f53b1770f9ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page