diff --git a/choose-cn.sh b/choose-cn.sh index 0319150..21d8c08 100644 --- a/choose-cn.sh +++ b/choose-cn.sh @@ -19,9 +19,17 @@ do # 如果延迟时间小于 150ms if (( $(echo "$ping_time < 150" | bc -l) )); then - echo "Ping to $ip successful with a latency of $ping_time ms" - # 将小于 150ms 的 IP 写入 ip_use.txt - echo "$ip" >> ip_use.txt + # 检查 IP 地址与 Cloudflare 的连通性 + status_code=$(curl --resolve cloudflare.com:443:$ip --insecure https://cloudflare.com/cdn-cgi/trace -o /dev/null -w '%{http_code}' -s) + + # 如果 HTTP 状态码为 200 + if [ $status_code -eq 200 ]; then + echo "Ping to $ip successful with a latency of $ping_time ms" + # 将小于 150ms 的 IP 写入 ip_use.txt + echo "$ip" >> ip_use.txt + else + echo "Ping to $ip discarded due to connectivity issues with Cloudflare" + fi else echo "Ping to $ip discarded due to high latency of $ping_time ms" fi