github: https://github.com/lidotcircle/portForwarder
应用协议复用器是一种工具,它允许您根据客户端发送的第一个数据包中的正则表达式模式匹配,将 TCP 或 UDP 流量转发到不同的地址。
可以从源代码构建此工具,或者从发布页面下载名为 portfd 的预编译二进制文件。
可以使用简单的命令行参数运行 portfd ,请使用以下语法:portfd <local-bind> <remote>
。
在这种情况下,需要指定监听地址和远程地址。
对于更高级的用法,portfd 可以使用支持更复杂规则的配置文件启动。以下是一个使用 YAML 格式的配置文件示例:
forwarders:
- local: 0.0.0.0:8808
# 指定 'remoteMap' 或 'remote'
remoteMap:
- pattern: "[http:localhost]"
remote: 192.168.44.43:5445
- pattern: "[https:baidu.com]"
remote: "39.156.66.10:443"
- pattern: "[ssh]"
remote: "192.168.44.43:22"
- pattern: .*
remote: 192.168.100.46:3389
remote: <remote-address/127.0.0.1:2233>
enable_tcp: true # 默认为 true
enable_udp: true # 默认为 true
conn_bufsize: 2MB
max_connections: 10000 # 可选
allow_nets: # 可选的白名单
- 127.0.0.0/24
pattern
字段支持四种格式,所有格式都将转换为正则表达式:
1
happyn 361 天前 1
很有用的小工具,这样一些服务可以根据流量特征,做负载均衡了;
|
2
Tink 361 天前 1
6
一个端口既翻墙又跑网站顺便还能 ssh |
3
myqoo 361 天前 1
这个用 iptables 可以实现吗?
|
4
ppxppx OP @myqoo #3 应该不行,这个需要根据流量的内容来决定转发的目标,我问 chatgpt 得到的答案是 iptable 不支持这个功能。
``` No, iptables cannot directly route traffic based on the content of the traffic. iptables is a tool used for configuring the firewall rules in the Linux kernel's netfilter framework. It primarily operates at the network layer (Layer 3) and transport layer (Layer 4) of the network stack, inspecting factors such as source and destination IP addresses, ports, and protocols. ``` 而且这个工具用 Rust 写的,所以可以在 Windows 下用。 |
6
listenfree 361 天前 1
nftables 应该可行吧,昨天学了下,感觉比 iptables 简单。
|
8
ppxppx OP @listenfree #6 确实,而且 nftables 语法看着比 iptables 友好太多
|
9
leonshaw 361 天前
这是四层代理功能,iptables/nftables 应该不行。
不知道对第一个包不够的情况怎么处理的,比如 http url 过长导致 host 第一次没读到。 |
11
myqoo 361 天前
能用 iptables 的话可以保留原地址,否则日志里的原地址都是本地 ip 。
|
13
myqoo 361 天前
像 ngixn 里可以用 proxy_bind $remote_addr transparent; 转发时保留原始 IP ,不过这个特征貌似不是跨平台的。
|
17
leonshaw 361 天前
@ppxppx
是的,我之前写类似工具的时候就很头疼,不同协议区别太大了,加超时又可能影响体验。举个极端例子,telnet 客户端可能一开始根本不发数据包,而是先等服务端给个提示符。 |
19
leo97 361 天前 via Android
haproxy 可以做到
|
20
leeyuzhe 360 天前
不通协议的粘包如何处理?
|
25
etnperlong 358 天前
不错不错 已 star
想提个需求 看看大佬能不能支持一下 RDP ? |
26
ppxppx OP @etnperlong #25 我之前有看过相关文档,不过 rdp 的包有点复杂,还得再研究研究
|
27
ppxppx OP @etnperlong #25 刚刚加了对 rdp 的支持
|