Skip to content

Instantly share code, notes, and snippets.

@johan149
Last active January 26, 2023 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johan149/754f95421610f62f585d863f216e0b23 to your computer and use it in GitHub Desktop.
Save johan149/754f95421610f62f585d863f216e0b23 to your computer and use it in GitHub Desktop.
#!/bin/bash
# to use run the following
# wget -qO - https://gist.githubusercontent.com/johan149/754f95421610f62f585d863f216e0b23/raw/2578b078826e66c59e0bb68384c67aac67f0016d/sping | bash
declare -a list
list[0]=nj-us-ping.vultr.com
list[1]=il-us-ping.vultr.com
list[2]=ga-us-ping.vultr.com
list[3]=fl-us-ping.vultr.com
list[4]=tx-us-ping.vultr.com
list[5]=hon-hi-us-ping.vultr.com
list[6]=sjo-ca-us-ping.vultr.com
list[7]=lax-ca-us-ping.vultr.com
list[8]=mex-mx-ping.vultr.com
list[9]=wa-us-ping.vultr.com
list[10]=tor-ca-ping.vultr.com
list[11]=fra-de-ping.vultr.com
list[12]=ams-nl-ping.vultr.com
list[13]=par-fr-ping.vultr.com
list[14]=lon-gb-ping.vultr.com
list[15]=mel-au-ping.vultr.com
list[16]=syd-au-ping.vultr.com
list[17]=sgp-ping.vultr.com
list[18]=hnd-jp-ping.vultr.com
list[19]=sel-kor-ping.vultr.com
list[20]=jnb-za-ping.vultr.com
list[21]=blr-in-ping.vultr.com
list[22]=del-in-ping.vultr.com
list[23]=bom-in-ping.vultr.com
list[24]=osk-jp-ping.vultr.com
list[25]=tx-us-ping.vultr.com
list[26]=mad-es-ping.vultr.com
list[27]=sto-se-ping.vultr.com
list[28]=scl-cl-ping.vultr.com
list[29]=sao-br-ping.vultr.com
# This part is to retrieve the latency of site the array and put it in the array like this : {latency}ms = {site}
array=$(for i in "${list[@]}"; do ping -c 1 $i | egrep -o "([0-9.]+) ms$" -m 1 | sed -n -e "s/ms/ms = ${i}/p" ; done)
# Sorting the array
IFS=$'\n' sorted=($(sort -n <<<"${array[*]}")); unset IFS
# This part is just to reverse the latency and the host
for i in "${sorted[@]}"; do echo $i | sed -E "s/([0-9.]+ ms) = ([a-z.]+)/\2 : \1/" ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment