#!/bin/bash # 定义文件名 IP_FILE="ip.txt" IP_USE_FILE="ip_use.txt" # Step 1: 使用 dig 命令获取 sniproxy.youoffer.net 的所有IP地址,并写入到 ip.txt 文件中 dig +short sniproxy.youoffer.net > "$IP_FILE" # 检查是否成功获取到了IP地址 if [[ ! -s "$IP_FILE" ]]; then echo "Failed to retrieve IP addresses." exit 1 fi # 读取文件中的每个IP地址,并对每个地址进行测试 while IFS= read -r IP_ADDRESS; do # 忽略空行 if [[ -z "$IP_ADDRESS" ]]; then continue fi echo Testing IP address: $IP_ADDRESS"" # Step 3: 使用 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}") # Step 4: 检查 HTTP 响应码 if [[ "$HTTP_RESPONSE" == "200" ]]; then echo "$IP_ADDRESS" >> "$IP_USE_FILE" echo "Success: HTTP 200 OK" else echo "Failed: HTTP response was $HTTP_RESPONSE or connection timed out " fi done < "$IP_FILE"