Last active
June 2, 2024 12:27
-
-
Save mohd-akram/4e426917f3c27394a7561ce3fe2a703a to your computer and use it in GitHub Desktop.
A utility to ping different regions of cloud providers
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/sh | |
| set -eu | |
| set -o pipefail 2>/dev/null || : | |
| aws_regions="\ | |
| af-south-1 ap-east-1 ap-northeast-1 ap-northeast-2 ap-northeast-3 | |
| ap-south-1 ap-southeast-1 ap-southeast-2 ca-central-1 eu-central-1 eu-north-1 | |
| eu-south-1 eu-west-1 eu-west-2 eu-west-3 me-south-1 sa-east-1 us-east-1 | |
| us-east-2 us-west-1 us-west-2 | |
| " | |
| docean_regions="\ | |
| ams3 blr1 fra1 nyc3 sfo2 sfo3 sgp1 | |
| " | |
| vultr_regions="\ | |
| bom-in sel-kor sgp hnd-jp mel-au syd-au ams-nl fra-de lon-gb mad-es par-fr | |
| sto-se waw-pl ga-us il-us tx-us hon-hi-us lax-ca-us mex-mx fl-us nj-us wa-us | |
| sjo-ca-us tor-ca sao-br | |
| " | |
| linode_regions="\ | |
| atlanta dallas frankfurt fremont london mumbai1 newark singapore syd1 tokyo2 | |
| toronto1 | |
| " | |
| oracle_regions="\ | |
| ap-chuncheon-1 ap-hyderabad-1 ap-melbourne-1 ap-mumbai-1 ap-osaka-1 ap-seoul-1 | |
| ap-sydney-1 ap-tokyo-1 ca-montreal-1 ca-toronto-1 eu-amsterdam-1 eu-frankfurt-1 | |
| eu-zurich-1 me-dubai-1 me-jeddah-1 sa-santiago-1 sa-saopaulo-1 uk-cardiff-1 | |
| uk-london-1 us-ashburn-1 us-phoenix-1 us-sanjose-1 | |
| " | |
| pingregion() { | |
| printf "%-7s %-15s %8.3f\n" "$1" "$2" "$(pingurl "` | |
| case $1 in | |
| aws) printf 'ec2.%s.amazonaws.com' "$2" ;; | |
| docean) printf '%s.digitaloceanspaces.com' "$2" ;; | |
| vultr) printf '%s-ping.vultr.com' "$2" ;; | |
| linode) printf 'speedtest.%s.linode.com' "$2" ;; | |
| oracle) printf 'objectstorage.%s.oraclecloud.com' "$2" | |
| ;; | |
| esac | |
| `")" | |
| } | |
| pingurl() { | |
| ping -c5 -- "$1" | awk ' | |
| match($0, /time=[^[:space:]]+/) { | |
| ++count | |
| sum += substr($0, RSTART+5, RLENGTH-5) | |
| } | |
| END { print sum / count }' | |
| } | |
| if [ "$#" = 0 ]; then | |
| set aws docean vultr linode oracle | |
| fi | |
| for provider; do | |
| case $provider in | |
| aws) printf "aws %s\n" $aws_regions ;; | |
| docean) printf "docean %s\n" $docean_regions ;; | |
| vultr) printf "vultr %s\n" $vultr_regions ;; | |
| linode) printf "linode %s\n" $linode_regions ;; | |
| oracle) printf "oracle %s\n" $oracle_regions ;; | |
| esac | |
| done | | |
| while read provider region; do | |
| pingregion "$provider" "$region" & | |
| done | | |
| sort -k3,3n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment