From 5d2b5b7414e4c8e770e25918c44290a85c88a384 Mon Sep 17 00:00:00 2001 From: chunzhi Date: Mon, 22 Jan 2024 20:54:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20choose-cn.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- choose-cn.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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