First ping, than connect

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
dd
OpenVpn Newbie
Posts: 1
Joined: Tue Apr 17, 2012 8:37 am

First ping, than connect

Post by dd » Tue Apr 17, 2012 8:43 am

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... :roll:

THX dd

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: First ping, than connect

Post by janjust » Tue Apr 17, 2012 1:08 pm

this is not built into openvpn - you'd have to script it yourself.

frankuit
OpenVPN User
Posts: 34
Joined: Thu Apr 12, 2012 12:12 pm

Re: First ping, than connect

Post by frankuit » Wed Apr 18, 2012 6:29 pm

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]
Kind regards,
Frank Uittenbosch

Post Reply