#!/bin/bash echo LIST_URL="https://mirrors.kvm-i7.host/serverlist.txt" FILE_SIZE_BYTES=$((256*1024*1024)) FILE_SIZE_MB=$(awk "BEGIN{print $FILE_SIZE_BYTES/1024/1024}") process_latencies() { local lat_list=("$@") if [ ${#lat_list[@]} -eq 0 ]; then printf "%8.2f ms (jitter: 0.00ms, low: 0.00ms, high: 0.00ms)" "0.00" "0.00" "0.00" "0.00" return fi local sum=0 local low=${lat_list[0]} local high=${lat_list[0]} for lat in "${lat_list[@]}"; do sum=$(awk "BEGIN{print $sum+$lat}") if [ $(awk -v lat="$lat" -v low="$low" 'BEGIN{print (lathigh)}') -eq 1 ]; then high=$lat; fi done local avg=$(awk "BEGIN{print $sum/${#lat_list[@]}}") local jitter=$(awk "BEGIN{print $high-$low}") printf "%8.2f ms (jitter: %.2fms, low: %.2fms, high: %.2fms)" "$avg" "$jitter" "$low" "$high" } idle_latency_test() { local url="$1" local count=10 local successes=0 local latencies=() printf "Idle Latency: " for ((i=0; i/dev/null) if [ -n "$lat_s" ] && [ "$(echo "$lat_s > 0" | bc)" -eq 1 ]; then latencies+=($(awk "BEGIN{print $lat_s*1000}")) ((successes++)) fi sleep 0.2 done packet_loss=$(awk "BEGIN{print (1-($successes/$count))*100}") process_latencies "${latencies[@]}" printf "\n" } transfer_test() { local mode=$1 local url="$2" local file="/tmp/speedtest_file.bin" local start=$(date +%s.%N) local latencies=() local pings=0 head -c $FILE_SIZE_BYTES /dev/zero > "$file" if [ "$mode" = "Download" ]; then printf " Download: " wget -qO "$file" "$url/download" & local pid=$! else printf " Upload: " curl -s -X POST --data-binary @"$file" "$url/upload" -o /dev/null & local pid=$! fi while kill -0 $pid 2>/dev/null; do if (( pings % 5 == 0 )); then local lat_s=$(curl -s -m 2 -o /dev/null -w "%{time_total}" "$url/ping" 2>/dev/null) if [ -n "$lat_s" ] && [ "$(echo "$lat_s > 0" | bc)" -eq 1 ]; then latencies+=($(awk "BEGIN{print $lat_s*1000}")) fi fi ((pings++)) sleep 0.2 done wait $pid local end=$(date +%s.%N) local duration=$(awk "BEGIN{print $end-$start}") local speed=$(awk "BEGIN{printf \"%.2f\", ($FILE_SIZE_BYTES*8/1000000)/$duration}") printf "%8.2f Mbps (data used: %.1f MB)\n" "$speed" "$FILE_SIZE_MB" printf " " process_latencies "${latencies[@]}" printf "\n" rm -f "$file" } echo " Speedtest by E5-Compute.host" ISP=$(curl -s ipinfo.io/org | cut -d ' ' -f2-) [ -z "$ISP" ] && ISP="custom" mapfile -t servers < <(curl -s "$LIST_URL" | grep -v '^#' | sed '/^[[:space:]]*$/d') best_latency=9999 for s in "${servers[@]}"; do IFS=: read -r ip port name <<< "$s" ipport="$ip:$port" t=$(curl -s -m 5 -o /dev/null -w "%{time_total}" "$ipport/ping" 2>/dev/null || echo 9999) if [ $(awk -v t="$t" -v best="$best_latency" 'BEGIN{print (t