更新 choose-cn-v2.sh

加入延迟检测
This commit is contained in:
chunzhi 2024-02-08 19:05:13 +08:00
parent 02f0e090d3
commit ec956e6b22

View File

@ -23,6 +23,35 @@ dig cf.youoffer.net A +short > ip.txt
# 创建一个新的文件 final_ips.txt
touch final_ips.txt
#延迟检测部分
while IFS= read -r ip
do
echo "Checking latency for $ip"
# 使用 ping 命令检查延迟
ping_result=$(ping -c 1 -W 1 "$ip" 2>&1)
ping_status=$?
# 如果 ping 成功
if [ $ping_status -eq 0 ]; then
# 提取延迟时间
ping_time=$(echo "$ping_result" | grep time= | cut -d'=' -f 4 | cut -d' ' -f 1)
# 显示延迟时间
echo "Latency for $ip is $ping_time ms"
# 如果延迟时间大于 200ms
if (( $(echo "$ping_time > 200" | bc -l) )); then
echo "Latency for $ip is too high, discarding."
# 从 ip.txt 删除延迟时间大于 200ms 的 IP
sed -i "/$ip/d" ip.txt
fi
else
echo "Ping to $ip failed or timed out."
# 从 ip.txt 删除无法 ping 通的 IP
sed -i "/$ip/d" ip.txt
fi
done < ip.txt
# 读取 ip.txt 中的每个 IP 地址进行下载测试
while IFS= read -r ip
do