Created
March 25, 2026 11:57
-
-
Save iam4x/1cf54cc3186a33a69cac229b32bc683e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| IPS=( | |
| 64.31.48.111 | |
| 64.31.51.137 | |
| 180.189.55.18 | |
| 180.189.55.19 | |
| 34.84.25.59 | |
| 34.146.230.150 | |
| 13.230.78.76 | |
| 54.248.41.39 | |
| 52.68.71.160 | |
| 13.114.116.44 | |
| 79.127.159.173 | |
| 79.127.159.174 | |
| 23.81.40.69 | |
| 157.90.207.92 | |
| 109.123.230.189 | |
| 31.223.196.172 | |
| 31.223.196.238 | |
| 91.134.71.237 | |
| 57.129.140.247 | |
| 67.213.123.85 | |
| 72.46.87.141 | |
| 199.254.199.12 | |
| 199.254.199.54 | |
| 45.250.255.111 | |
| 109.94.99.131 | |
| 23.81.41.3 | |
| 15.235.231.247 | |
| 199.254.199.48 | |
| 199.254.199.52 | |
| 15.235.232.101 | |
| 54.168.150.28 | |
| 54.64.2.87 | |
| 52.193.108.65 | |
| 54.65.106.241 | |
| 54.238.174.48 | |
| 18.180.228.50 | |
| 57.181.193.239 | |
| 35.190.230.32 | |
| 54.199.122.133 | |
| 13.158.244.192 | |
| 43.207.77.116 | |
| 35.79.116.97 | |
| 13.158.102.147 | |
| 116.199.229.233 | |
| 35.72.88.240 | |
| 45.76.206.35 | |
| 218.33.8.227 | |
| 35.77.205.141 | |
| ) | |
| TMP_RESULT="nc_results.txt" | |
| > "$TMP_RESULT" | |
| for IP in "${IPS[@]}"; do | |
| SUM=0 | |
| CNT=0 | |
| for i in {1..10}; do | |
| # Use Bash 'time' and parse elapsed time via TIMEFORMAT | |
| { | |
| TIMEFORMAT=%R | |
| T=$( { time nc -vz -w 2 "$IP" 4001 >/dev/null 2>&1; } 2>&1 ) | |
| } | |
| # Only count on successful connection (nc returns 0) | |
| if [ $? -eq 0 ] && [[ $T =~ ^[0-9]+(\.[0-9]+)?$ ]]; then | |
| SUM=$(echo "$SUM + $T" | bc) | |
| CNT=$((CNT+1)) | |
| fi | |
| done | |
| if [ "$CNT" -gt 0 ]; then | |
| AVG=$(echo "scale=4; $SUM / $CNT" | bc) | |
| else | |
| AVG="NaN" | |
| fi | |
| printf "%s %s (%s/%s)\n" "$AVG" "$IP" "$CNT" 10 >> "$TMP_RESULT" | |
| echo "Tested $IP: avg=${AVG}s ($CNT/10 successes)" | |
| done | |
| echo -e "\n=== Sorted Results (Fastest to Slowest, avg seconds per connect) ===" | |
| sort -n "$TMP_RESULT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment