Page 1 of 1
First ping, than connect
Posted: Tue Apr 17, 2012 8:43 am
by dd
Hi all,
i got a question...
Is it possible that, if i have different servers, openvpn is testing the speed (ping) and than connects
to the fastest.
Like, ping server1, ping server2, ping server3...server2 responds more quickly, then use server2.conf...
I hope its understandable...
THX dd
Re: First ping, than connect
Posted: Tue Apr 17, 2012 1:08 pm
by janjust
this is not built into openvpn - you'd have to script it yourself.
Re: First ping, than connect
Posted: Wed Apr 18, 2012 6:29 pm
by frankuit
On linux,I did that, using fping:
my script:
Code: Select all
#!/bin/bash
#create tmp file:
>/tmp/ping-result
#Define your OpenVPN hosts in HOSTS
HOSTS=( '192.168.20.30' '172.16.30.20' 'server1.example.com' )
ELEMENTS=${#HOSTS[@]}
# echo each element in array
# for loop
for (( i=0;i<$ELEMENTS;i++)); do
RESULT[${i}]=`fping -e ${HOSTS[${i}]}`
echo ${RESULT[${i}]} |awk {'print $4, $1'} |cut -c2-32>>/tmp/ping-result
done
#Now, return the host with the smallest PING
#Or, display DEBUG output
#VPNHOST=`cat /tmp/ping-result |sort -h `
VPNHOST=`cat /tmp/ping-result |sort -h |head -1 |cut -d " " -f2`
echo $VPNHOST
#CLEAN up tmp files:
rm /tmp/ping-result
Now, Using the variable $VPNHOST, You can use that to start your OpenVPN Connect command.
Kind regards,
Frank Uittenbosch
[script edited by dazo, to not use public IP addresses nor official hostname ... some people are stupid enough to run such scripts without modifying them]