62 lines
2.0 KiB
Bash
62 lines
2.0 KiB
Bash
|
|
#!/bin/bash
|
|||
|
|
# mihomo 代理健康检查 - Polymarket 专用
|
|||
|
|
# 逻辑:当前节点能下单就不换;不能下单就在日本/香港节点之间切换
|
|||
|
|
# cron 每 5 分钟跑一次
|
|||
|
|
|
|||
|
|
API="http://127.0.0.1:9090"
|
|||
|
|
PROXY="http://127.0.0.1:7890"
|
|||
|
|
|
|||
|
|
# 测试当前节点能否通过 Polymarket geo-gate(下单检测,不是读取检测)
|
|||
|
|
# 用 POST /order 测,403=被block,401=通过(到认证层了)
|
|||
|
|
test_geo() {
|
|||
|
|
code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 -x $PROXY \
|
|||
|
|
-X POST "https://clob.polymarket.com/order" \
|
|||
|
|
-H "Content-Type: application/json" \
|
|||
|
|
-d '{}' 2>/dev/null)
|
|||
|
|
# 401 = 通过 geo-gate(到认证层了),403 = 被 block
|
|||
|
|
if [ "$code" = "401" ] || [ "$code" = "400" ]; then
|
|||
|
|
return 0 # 能下单
|
|||
|
|
fi
|
|||
|
|
return 1 # 不能下单
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 1. 测当前节点能不能下单
|
|||
|
|
if test_geo; then
|
|||
|
|
exit 0 # 能下单,不换
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
# 2. 不能下单,在日本和香港节点之间找能用的
|
|||
|
|
# 只选日本/香港/韩国/台湾(Polymarket 允许的地区)
|
|||
|
|
nodes=$(curl -s "$API/proxies" | python3 -c "
|
|||
|
|
import sys, json
|
|||
|
|
d = json.load(sys.stdin)
|
|||
|
|
skip = {'DIRECT','REJECT','自动选择','故障转移','良心云','GLOBAL',
|
|||
|
|
'剩余流量','套餐到期'}
|
|||
|
|
# 只允许的地区关键词(日本/香港最稳定)
|
|||
|
|
allowed = ['日本', 'JP', 'Japan', '香港', 'HK', 'Hong Kong']
|
|||
|
|
for name, info in d.get('proxies', {}).items():
|
|||
|
|
if name in skip:
|
|||
|
|
continue
|
|||
|
|
if info.get('type') in ('Selector','URLTest','Fallback','LoadBalance'):
|
|||
|
|
continue
|
|||
|
|
# 只选允许地区的节点
|
|||
|
|
if not any(k in name for k in allowed):
|
|||
|
|
continue
|
|||
|
|
print(name)
|
|||
|
|
")
|
|||
|
|
|
|||
|
|
# 3. 逐个试,找到能下单的就切
|
|||
|
|
for node in $nodes; do
|
|||
|
|
curl -s -X PUT "$API/proxies/GLOBAL" \
|
|||
|
|
-H "Content-Type: application/json" \
|
|||
|
|
-d "{\"name\":\"$node\"}" > /dev/null
|
|||
|
|
sleep 2
|
|||
|
|
if test_geo; then
|
|||
|
|
logger "mihomo-healthcheck: switched to $node (previous node geo-blocked)"
|
|||
|
|
exit 0
|
|||
|
|
fi
|
|||
|
|
done
|
|||
|
|
|
|||
|
|
logger "mihomo-healthcheck: ALL JP/HK nodes failed - check mihomo or subscription"
|
|||
|
|
exit 1
|