Skip to main content

Tunnel 内网穿透客户端 - 支持 IPv6/IPv4 P2P 直连与中继双模式

Project description

Tunnel

类似 ngrok 的内网穿透服务,支持 IPv6/IPv4 P2P 直连与服务端中继双模式。

将本地服务暴露到公网,通过固定域名访问,无需公网 IP。

快速开始

1. 安装客户端

pip install tunnel-p2p-client

2. 启动隧道

tunnel-p2p-client --key YOUR_TOKEN --port 8080

连接成功后,你会得到一个公网地址,例如 http://aicq.online:7739/EAH3WR2X,任何人都可以通过这个地址访问你本地的 8080 端口服务。

客户端参数

参数 说明 默认值
-k, --key 认证令牌(必填,在管理面板创建隧道时获取) -
-p, --port 本地服务端口 8080
-s, --server 服务器地址 aicq.online:7739
--host 本地服务地址 localhost
--p2p-port P2P 直连监听端口 与 --port 相同
--no-p2p 禁用 P2P,强制使用中继模式 false

使用示例

# 将本地 3000 端口暴露到公网
tunnel-p2p-client -k YOUR_TOKEN -p 3000

# 指定自定义服务器
tunnel-p2p-client -k YOUR_TOKEN -p 80 -s your-server.com:7739

# 强制使用中继模式(禁用 P2P)
tunnel-p2p-client -k YOUR_TOKEN -p 8080 --no-p2p

P2P 模式

默认启用,自动按优先级选择最佳连接方式:

优先级 模式 说明
1 IPv6 直连 公网 IPv6 无 NAT,直接连接,延迟最低
2 UPnP IPv4 路由器自动端口映射,非 CGNAT 环境可用
3 中继模式 流量经服务器转发,任何网络环境都可用

P2P 直连成功后,访问者的流量不经过服务器,直接连接到你的机器,降低服务器负载。

服务端部署

一键部署

git clone https://github.com/ctz168/tunnel.git
cd tunnel/server
sudo bash install.sh

部署完成后:

  • 管理面板:http://your-domain:7739
  • 在管理面板创建隧道,获取认证令牌给客户端使用

服务管理(systemd)

systemctl start tunnel      # 启动
systemctl stop tunnel       # 停止
systemctl restart tunnel    # 重启
systemctl status tunnel     # 查看状态
journalctl -u tunnel -f     # 查看日志

从源码运行

git clone https://github.com/ctz168/tunnel.git
cd tunnel
python -m tunnel_client --key YOUR_TOKEN --port 8080

License

MIT

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

tunnel_p2p_client-2.4.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

tunnel_p2p_client-2.4.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file tunnel_p2p_client-2.4.0.tar.gz.

File metadata

  • Download URL: tunnel_p2p_client-2.4.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for tunnel_p2p_client-2.4.0.tar.gz
Algorithm Hash digest
SHA256 5255e4c90c32f067077e95ebdf694213a16bfe4a9f505a895d6fab19d906e55e
MD5 112ee343b818c8cc9a153bcbdeb18918
BLAKE2b-256 d7e5d4008c1691457d201acee15ba8cb0d2d2475edb6d3e55db15c92fb01b1a6

See more details on using hashes here.

File details

Details for the file tunnel_p2p_client-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tunnel_p2p_client-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e64457a9c6b07dd57b86e8daad90223e4c1a61fbd02089fcd0a6219f8d21757
MD5 1876414feb0a22c0eb823521c24beca5
BLAKE2b-256 9b03045dfce3f0aac0560a0b01b7d5cc210c0dbb03bc149a97ac314d0c031737

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