feat: add SOCKS5 proxy support and enhance configuration

- Introduced SOCKS5 proxy functionality with separate ports for random rotation and lowest latency.
- Updated `.env.example` and `docker-compose.yml` to include SOCKS5 port configurations.
- Enhanced `main.go` to initialize and start SOCKS5 servers alongside existing HTTP proxies.
- Revised README to document new SOCKS5 features, including usage examples and testing scripts.
- Improved proxy selection logic in the storage layer to support SOCKS5 protocol.
This commit is contained in:
isboyjc
2026-03-30 01:02:00 +08:00
parent cede441015
commit b1555a702f
11 changed files with 1052 additions and 93 deletions

View File

@@ -7,6 +7,7 @@
| 脚本 | 语言 | 依赖 | 运行模式 | 推荐度 |
|------|------|------|----------|--------|
| `test_proxy.sh` | Bash | curl + Python3 | 持续运行 | ⭐⭐⭐ |
| `test_socks5.sh` | Bash | curl + Python3 | 持续运行 | ⭐⭐⭐ |
| `test_proxy.go` | Go | `golang.org/x/net/proxy` | 持续运行 | ⭐⭐ |
| `test_proxy.py` | Python | `requests`, `pysocks` | 持续运行 | ⭐⭐ |
@@ -14,15 +15,24 @@
### Bash 脚本(推荐)
**HTTP 代理测试**
```bash
# 从项目根目录运行(持续测试 HTTP
./test/test_proxy.sh
# 测试 7777 端口(随机轮换
./test/test_proxy.sh 7777
# 测试 HTTP 协议
./test/test_proxy.sh http
# 测试 7776 端口(最低延迟)
./test/test_proxy.sh 7776
# 测试 SOCKS5 协议
./test/test_proxy.sh socks5
# 按 Ctrl+C 停止并查看统计
```
**SOCKS5 代理测试**
```bash
# 测试 7779 端口(随机轮换)
./test/test_socks5.sh 7779
# 测试 7780 端口(最低延迟)
./test/test_socks5.sh 7780
# 按 Ctrl+C 停止并查看统计
```
@@ -69,9 +79,9 @@ python test/test_proxy.py
## 🔀 测试不同端口策略
```bash
# 对比两个端口的行为差异:
### HTTP 代理端口对比
```bash
# 随机轮换模式 - IP 高度分散
./test/test_proxy.sh 7777
@@ -83,6 +93,22 @@ python test/test_proxy.py
- **7777 端口**:每次请求的出口 IP 应该不同(证明在轮换)
- **7776 端口**:连续多次请求的出口 IP 基本相同(证明固定使用最优代理)
### SOCKS5 代理端口对比
```bash
# 随机轮换模式 - IP 高度分散
./test/test_socks5.sh 7779
# 最低延迟模式 - 固定使用最快代理
./test/test_socks5.sh 7780
```
**观察要点**
- **7779 端口**:每次连接的出口 IP 应该不同
- **7780 端口**:连续多次连接的出口 IP 基本相同
> 💡 **提示**SOCKS5 测试脚本使用 `-k` 参数跳过 SSL 证书验证,因为免费上游代理常有证书问题。生产环境建议使用质量更好的付费代理。
## 🔍 预期输出
```

View File

@@ -4,6 +4,8 @@
# 按 Ctrl+C 停止测试
# 用法: ./test_proxy.sh [端口号默认7777]
# PROXY_HOST="192.227.184.201"
# PROXY_HOST="proxy.amux.ai"
PROXY_HOST="127.0.0.1"
PROXY_PORT="${1:-7777}"
TEST_URL="http://ip-api.com/json/?fields=countryCode,query"

75
test/test_socks5.sh Executable file
View File

@@ -0,0 +1,75 @@
#!/bin/bash
###
# @LastEditTime: 2026-03-29 23:26:29
# @Description: ...
# @Date: 2026-03-29 23:14:32
# @Author: isboyjc
# @LastEditors: isboyjc
###
# GoProxy SOCKS5 代理测试脚本
# 用法: ./test_socks5.sh [端口号默认7779]
PROXY_HOST="${PROXY_HOST:-127.0.0.1}"
PROXY_PORT="${1:-7779}"
TEST_URL="https://httpbin.org/ip"
DELAY=1
# 统计变量
total=0
success=0
fail=0
# 获取毫秒时间戳(兼容 macOS 和 Linux
get_ms_time() {
python3 -c 'import time; print(int(time.time() * 1000))'
}
# 国家代码转 emoji 旗帜
country_to_emoji() {
local country_code="$1"
if [ -z "$country_code" ] || [ "$country_code" = "null" ]; then
echo "🌐"
return
fi
local first="${country_code:0:1}"
local second="${country_code:1:1}"
python3 -c "print(chr(127462 + ord('$first') - ord('A')) + chr(127462 + ord('$second') - ord('A')))"
}
# 捕获 Ctrl+C 信号
trap ctrl_c INT
function ctrl_c() {
echo ""
echo "---"
loss_rate=$(awk "BEGIN {printf \"%.1f\", ($total - $success)/$total*100}")
echo "$total requests transmitted, $success received, $((total - success)) failed, ${loss_rate}% packet loss"
exit 0
}
echo "SOCKS5 PROXY ${PROXY_HOST}:${PROXY_PORT}: continuous mode"
echo ""
while true; do
total=$((total + 1))
# 使用 curl 的 SOCKS5 支持(-k 跳过 SSL 验证,因为免费代理证书常有问题)
start=$(get_ms_time)
response=$(curl -s -k --socks5-hostname ${PROXY_HOST}:${PROXY_PORT} ${TEST_URL} --max-time 10 2>&1)
end=$(get_ms_time)
latency=$((end - start))
if echo "$response" | grep -q '"origin"'; then
success=$((success + 1))
origin=$(echo "$response" | grep -o '"origin":"[^"]*"' | cut -d'"' -f4 | cut -d',' -f1)
country=$(curl -s "http://ip-api.com/json/${origin}?fields=countryCode" 2>/dev/null | grep -o '"countryCode":"[^"]*"' | cut -d'"' -f4)
emoji=$(country_to_emoji "$country")
echo "socks5 #${total}: ${origin} ${emoji} ${country} (${latency}ms)"
else
fail=$((fail + 1))
echo "socks5 #${total}: request failed"
fi
sleep $DELAY
done