1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#!/bin/bash # 服务器 IP 列表和对应的域名 servers=( "154.8.141.27 api.9kvr.cn" "49.232.211.54 api.9kvr.cn" "192.144.228.145 api.9kvr.cn" "62.234.66.75 api.9kvr.cn" "101.42.45.53 api.9kvr.cn" # ... 可以继续添加更多服务器 ) # 测试路径 test_path="/api/city/getNextCityNew" # 报警接口 URL 模板 alarm_url_template="https://vr.he29.com/xxx/xxx.html?ip=%s&code=%s" # 测试每个服务器的 URL for server in "${servers[@]}"; do ip=$(echo $server | cut -d' ' -f1) domain=$(echo $server | cut -d' ' -f2) url="https://$domain$test_path" echo "Testing $url via IP $ip..." # 使用 --resolve 选项在 curl 中指定 IP 解析,并设置超时时间为 10 秒 start_time=$(date +%s%3N | awk '{print int($1)}') response=$(curl -s -w "%{http_code}" -o /dev/null --resolve "$domain:80:$ip" $url) end_time=$(date +%s%3N | awk '{print int($1)}') duration=$(echo "scale=3; ($end_time - $start_time)" | bc) time=$(curl -s $url | jq -r '.time') if [ "$response" -eq 200 ]; then echo "Success: $url returned HTTP $response, IP: $(curl -s $url | jq -r '.ip'), Duration: $duration ms Time: $time" else echo "Error: $url returned HTTP $response, IP: $(curl -s $url | jq -r '.ip'), Duration: $duration ms Time: $time" # 构造报警接口的完整 URL alarm_url=$(printf "$alarm_url_template" "$ip" "$response") # 调用报警接口 curl -s --data-urlencode "ip=$ip" --data-urlencode "code=$response" "$alarm_url" fi echo "" done |