Last active
January 5, 2020 07:41
-
-
Save pacmac/a65cc82b89caa67446b73d52eb55514a to your computer and use it in GitHub Desktop.
expressvpn fastest host
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/ash | |
# | |
# /usr/share/scripts/xvpnping.sh yes | |
# expressvpn fastest host script | |
# | |
# /etc/openvpn/hosts" | |
# uk-berkshire-2-ca-version-2.expressnetw.com | |
# uk-east-london-ca-version-2.expressnetw.com | |
# uk-london-ca-version-2.expressnetw.com | |
# uk-kent-ca-version-2.expressnetw.com | |
# | |
# /etc/openvpn/host" | |
# uk-berkshire-2-ca-version-2.expressnetw.com | |
# | |
# echo "config /etc/openvpn/host" >> /etc/openvpn/openvpn.conf | |
# | |
## Initial Defaults | |
Smallest=1000000 | |
Server="" | |
## Params | |
Tolerance=5 | |
Pings=4 | |
## Files | |
input="/etc/openvpn/hosts" | |
output="/etc/openvpn/host" | |
## Ping Function | |
func_ping () { | |
PingMs1=`ping -c $Pings -q -i .2 $myHost | grep avg | awk -F'/' '{print $5}' | sed -e "s/ ms//"` | |
PingMs=${PingMs1/./} | |
PingMs=$((PingMs / 1000)) | |
#echo "$myHost $PingMs" | |
} | |
## Get Current Host | |
_host=$(cat $output | tr -d "\n" | tr -d "\r") | |
host=$(echo $_host | awk '{print $2}') | |
# echo -e "CURRENT:\t$host" | |
## Get Current Host Ping | |
myHost=$host; | |
func_ping; | |
Smallest=$PingMs; | |
Server=$host; | |
echo "+++++++++++++++" | |
echo -e "CURRENT:\t$host ($Smallest)" | |
echo "+++++++++++++++" | |
## Loop Thru All Hosts | |
while IFS= read -r myHost | |
do | |
func_ping; | |
## Debugging | |
if [ ! -z $1 ]; then | |
echo -e "$PingMs\t\t$myHost" | |
fi | |
if [ "$((Smallest - PingMs))" -gt $Tolerance ];then | |
Server=$myHost | |
Smallest=$PingMs | |
fi; | |
done < "$input" | |
## STATUS | |
echo "+++++++++++++++" | |
echo -e "FASTEST:\t$Server ($Smallest)" | |
echo "+++++++++++++++" | |
HOST="remote $Server 1195" | |
#echo "$PingMs $Server" | |
## QUERY-ONLY | |
if [ ! -z $1 ]; then | |
echo "Query Only." | |
fi | |
## Do UPDATE | |
if [ "$Server" == "$host" ]; then | |
echo -e "NOCHANGE:\t$host ($Smallest)" | |
exit 0; | |
else | |
#Server="" | |
if [ -z $Server ]; then | |
echo "ERROR: Fastest Host is NOT set." | |
else | |
echo "UPDATE: $HOST" | |
echo $HOST > $output | |
/sbin/service openvpn stop; | |
sleep 2 | |
/sbin/service openvpn start; | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think
ping
command is not properly configured, i get errorI have manjaro OS