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.1.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.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tunnel_p2p_client-2.4.1.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.1.tar.gz
Algorithm Hash digest
SHA256 11b93d5d78175a579abb15d6a8dd8ea8865b90597406fa84e061e7563a991553
MD5 afc59ad3de58dd18792a656f4425fcb7
BLAKE2b-256 b604edc7ae9c3d86d39b417da040fe2edcec8e781a134fe7647202ac11cf163a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tunnel_p2p_client-2.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 350ee412920e40a46f161db5a1ce7b69671a64b875e5109bc103cf22d943bba2
MD5 a573f128b1c8fbf289d01e00841786f2
BLAKE2b-256 0eec16e78141388a22cfb863b2a5c6975e1d1ab8466e02507e839f0c236e5d7d

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