使用盒子优选ip并上传到github
目录
前提是在盒子中安装好git 和测速软件 https://github.com/XIU2/CloudflareSpeedTest 并且可以把结果推送到tg的bot
然后使用如下脚本即可测速,并且把IP上传到github 当作cm的优选API 参考cm部署代码 https://github.com/cmliu/edgetunnel
#!/bin/bash
# 進入工作目錄
cd /opt/data/cloudflarespeedtest || { echo "Directory not found"; exit 1; }
# -----------------------
# Telegram 配置
# -----------------------
TG_TOKEN="xxx"
TG_CHAT_ID="xxx"
# -----------------------
# 文件配置
# -----------------------
csv_file="result.csv"
output_ip_file="youxuanip.txt"
# -----------------------
# 日誌函數
# -----------------------
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
}
# -----------------------
# Telegram 推送函數
# -----------------------
push_tg() {
local message="$1"
curl -s -X POST "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" \
-d "chat_id=${TG_CHAT_ID}" \
-d "text=${message}" \
-d "parse_mode=Markdown" \
> /dev/null
}
# -----------------------
# 開始測速
# -----------------------
log "Start Cloudflare Speed Test..."
./cfst \
-url https://cdn.cloudflare.steamstatic.com/steam/apps/256843155/movie_max.mp4 \
-sl 3 \
-tl 500 \
-dn 10
# -----------------------
# 檢查測速結果
# -----------------------
if [ ! -s "$csv_file" ]; then
log "Error: $csv_file not generated."
push_tg "❌ *CFST測速失敗*:未生成結果文件"
exit 1
fi
log "Speed test finished. Extracting Top10 IP..."
# -----------------------
# 提取前10個IP
# -----------------------
best_ips=$(tail -n +2 "$csv_file" | head -n 10 | cut -d',' -f1)
if [ -z "$best_ips" ]; then
log "Error: Cannot extract IP"
push_tg "❌ *錯誤*:無法從 CSV 提取 IP"
exit 1
fi
# -----------------------
# 保存IP
# -----------------------
echo "$best_ips" > "$output_ip_file"
# 添加標籤,方便clash分类
sed -i 's/$/#本地韩国/' "$output_ip_file"
log "Top10 IP saved to $output_ip_file"
# -----------------------
# GitHub 自動推送
# -----------------------
log "Start GitHub push..."
git config --global http.sslVerify false
git add "$output_ip_file"
# 防止無變更 commit 失敗
git commit -m "Auto Update CF IPs: $(date '+%Y-%m-%d %H:%M:%S')" || true
if git push origin master -f; then
log "GitHub push success!"
# 取得前三個IP
top_ips=$(head -n 3 "$output_ip_file" | cut -d'#' -f1 | tr '\n' ' ')
tg_msg="🚀 *CF優選IP更新成功*
📍 標籤: #本地韩国
🔝 Top3: \`$top_ips\`
📦 GitHub: 已同步
⏰ $(date '+%Y-%m-%d %H:%M:%S')"
push_tg "$tg_msg"
else
log "GitHub push failed!"
push_tg "⚠️ *GitHub推送失敗*,請檢查網絡或權限"
fi
log "Script finished."下次准备把乌鸦大佬的区域IP拿出来给自己测速使用