Last active
June 13, 2020 04:49
-
-
Save Septem151/13cff7cf6a01082ac613b72e6509eb4d to your computer and use it in GitHub Desktop.
OSRS Ping Scanner
This file contains 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 | |
# BEGIN Progress bar code | |
_last_progress=-1 | |
# 0. Initialize | |
function progbar_init { | |
printf "Calculating world pings...\n" | |
tput cup `tput lines` 0 | |
_last_progress=-1 | |
} | |
# 1. Create ProgressBar function | |
# 1.1 Input is currentState($1) and totalState($2) | |
function progbar_show { | |
# Process data | |
let _progress=(${1}*100/${2}*100)/100 | |
# if [ $_progress -eq $_last_progress ]; then | |
# return | |
# fi | |
_last_progress=$_progress | |
let _done=(${_progress}*4)/10 | |
let _left=40-$_done | |
# Build progressbar string lengths | |
_fill=$(printf "%${_done}s") | |
_empty=$(printf "%${_left}s") | |
# 1.2 Build progressbar strings and print the ProgressBar line | |
# 1.2.1 Output example: | |
# 1.2.1.1 Progress : [▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇] 100% World: 316 | |
printf "\rProgress : [${_fill// /▇}${_empty// / }] ${_progress}%% World: ${3}" | |
tput cup `tput lines` $(( `tput cols` - 3 )) | |
} | |
# END Progress bar code | |
# Create temporary file for sorting purposes | |
pingfile=`openssl rand -base64 32 | tr -d /=+ | cut -c -16`".tmp" | |
touch "$pingfile" | |
trap 'rm $pingfile; printf "\n"; exit 1' SIGINT | |
progbar_init | |
skip_worlds=(1 8 16 26 35 71 72 79 80 81 82 83 84 85 93 94 97 98 99 100 101 \ | |
102 103 104 105 106 107 108 109 110 111 112 113 114 118 119 125 126 127 130 \ | |
131 132 133 134 135 136 137 138 139 140 141 142 151 152 153 154 155 156 157 \ | |
158 159 160 161 162 168 169 170 171 172 173 174 175 176 183) | |
start_world=1 | |
end_world=235 | |
for value in $(seq "${start_world}" "${end_world}") | |
do | |
found=0 | |
for item in ${skip_worlds[*]} | |
do | |
if [[ ${value} -eq ${item} ]] | |
then | |
found=1 | |
break | |
fi | |
done | |
if [[ ${found} -eq 0 ]] | |
then | |
world=$(( value + 300 )) | |
sum=0 | |
progbar_show ${value} ${end_world} ${world} | |
trials=1 | |
for i in $(seq 1 $trials) | |
do | |
worldping=`ping -c 1 "oldschool${value}.runescape.com" \ | |
| awk 'BEGIN {FS="[=]|[ ]"} NR==2 {print $11}'` | |
sum=$( echo "${sum}" + "${worldping}" | bc -l ) | |
#sleep 0.25 | |
done | |
avg=$( echo "${sum} / ${trials}" | bc -l ) | |
printf "World: ${world}\tPing: %.1f\n" ${avg} >> "$pingfile" | |
fi | |
done | |
printf "\r%*s" $COLUMNS | |
# Sort worlds by ping, lowest to highest | |
sort -k 4 -n -o "$pingfile" "$pingfile" | |
best_worlds=$(head -n 15 "$pingfile") | |
rm "$pingfile" | |
# Echo the best 15 worlds | |
printf "Best worlds:\n${best_worlds}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment