ws检测
This commit is contained in:
chunzhi 2024-02-12 11:43:19 +08:00
parent 866b58531b
commit dd9b272fe5

View File

@ -83,6 +83,46 @@ done < ip.txt
echo "Download tests completed. IPs with download speed >= 8Mbps are written to final_ips.txt"
# WebSocket 检测部分
IP_USE_FILE="ip_use.txt"
touch "$IP_USE_FILE"
# 读取 final_ips.txt 文件中的每个 IP 地址,并进行 WebSocket 测试
while IFS= read -r IP_ADDRESS; do
# 忽略空行
if [[ -z "$IP_ADDRESS" ]]; then
continue
fi
echo "Testing WebSocket connection for IP address: $IP_ADDRESS"
# 使用 curl 测试 WebSocket 连接
HTTP_RESPONSE=$(curl --include \
--no-buffer \
--max-time 5 \
--resolve speed.cloudflare.com:443:"$IP_ADDRESS" \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: speed.cloudflare.com" \
--header "Origin: https://speed.cloudflare.com" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
"https://speed.cloudflare.com/" --silent --output /dev/null --write-out "%{http_code}")
# 检查 HTTP 响应码
if [[ "$HTTP_RESPONSE" == "101" ]]; then
echo "$IP_ADDRESS" >> "$IP_USE_FILE"
echo "WebSocket connection success: HTTP 101 Switching Protocols"
else
echo "WebSocket connection failed: HTTP response was $HTTP_RESPONSE or connection timed out"
# 从 final_ips.txt 删除无法建立 WebSocket 连接的 IP
sed -i "/$IP_ADDRESS/d" final_ips.txt
fi
done < final_ips.txt
echo "WebSocket tests completed. IPs with successful WebSocket connections are written to $IP_USE_FILE"
# Cloudflare DDNS 更新部分
# 以下变量需要填写
API_KEY="your_cloudflare_global_api_key"
@ -132,7 +172,7 @@ do
else
echo "Failed to add DNS record for IP $ip"
fi
done < final_ips.txt
done < ip_use.txt
# 删除临时文件
rm -rf ip.txt final_ips.txt
rm -rf ip.txt final_ips.txt ip_use.txt