A small Python TCP reverse tunnel compatible with common frp/rathole config subsets.
Project description
py-frp
一个小型 Python 生态内网穿透工具,设计上参考 frp/rathole 的“服务端公网监听 + 客户端反向拨入”模型。当前版本专注 TCP 端口映射,支持服务端、客户端、frp 常见 TOML/INI 配置子集,以及 rathole 常见 TOML 配置子集。
安装
从 PyPI 安装:
pip install py-simple-nat-tunnel
从源码安装:
pip install .
开发模式安装:
pip install -e .
安装后会得到这些命令:
py-frp --version
py-frp server -c examples/frps.toml
py-frp client -c examples/frpc.toml
py-frps -c examples/frps.toml
py-frpc -c examples/frpc.toml
Windows 上如果提示 scripts 目录不在 PATH,也可以直接用:
python -m py_frp server -c examples/frps.toml
python -m py_frp client -c examples/frpc.toml
快速开始
服务端公网机器:
py-frp server -c examples/frps.toml
客户端内网机器:
py-frp client -c examples/frpc.toml
examples/frpc.toml 默认把客户端的 127.0.0.1:22 暴露到服务端的 0.0.0.0:6000。启动后从外部访问:
ssh -p 6000 user@your-server
frp 配置子集
服务端 frps.toml:
bindPort = 7000
[auth]
token = "change-me"
客户端 frpc.toml:
serverAddr = "your-server"
serverPort = 7000
[auth]
token = "change-me"
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000
也支持旧版 frp INI 的 [common] 和 TCP proxy section:
[common]
server_addr = your-server
server_port = 7000
token = change-me
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000
rathole 配置子集
服务端:
[server]
bind_addr = "0.0.0.0:2333"
default_token = "change-me"
[server.services.ssh]
bind_addr = "0.0.0.0:6000"
客户端:
[client]
remote_addr = "your-server:2333"
default_token = "change-me"
[client.services.ssh]
local_addr = "127.0.0.1:22"
提权
服务端启动时如果配置里有小于 1024 的监听端口,默认会通过 py-admin-launch 尝试提权一次。也可以显式控制:
py-frp server -c frps.toml --elevate
py-frp server -c frps.toml --no-auto-elevate
实现上会在重启命令后追加内部标记,保证最多只尝试一次,不会循环弹出提权请求。
当前范围
已支持:
- TCP 反向端口映射
- 多服务/多 proxy
- token 鉴权
- frp TOML 和 legacy INI 的常见 TCP 配置
- rathole TOML 的常见 TCP 配置
pip install .一键安装和 console scripts
暂不支持:
- UDP
- HTTP/HTTPS vhost
- frp 插件、负载均衡、STCP/XTCP
- rathole Noise/TLS 加密传输
- 多路复用;当前每个公网连接会建立一条独立 tunnel TCP
测试
python -m unittest discover -s tests -v
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_simple_nat_tunnel-0.1.0.tar.gz.
File metadata
- Download URL: py_simple_nat_tunnel-0.1.0.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fde04387a53b3000e344beb13edc950f4db273f1ce3160c558a4443b787cda0
|
|
| MD5 |
9338d36c24996944ec2219d535f70b9b
|
|
| BLAKE2b-256 |
ea811d94911b21452280c2cefcd6f1aff1af3c587e6e2ee199e1e2d7471146e2
|
File details
Details for the file py_simple_nat_tunnel-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_simple_nat_tunnel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6892f35a5fd3b4f557733ffea9bb8fec428cddd5cfe9a71b22e8a1f8578a148a
|
|
| MD5 |
561a3bc4a7d10dbd61d16532d9e809c1
|
|
| BLAKE2b-256 |
07f03744806afe15e3b9bff91735a0ed367e6e8cd09a7013400f58a8f29d90b2
|