Shell Script for "Fastest Server" feature

I have used Linux for a while, but I still haven’t yet delved into Bash. How would I write a shell script that would essentially do the “fastest server” feature manually?

It would need to do the following:

  • Ping the list of VyprVPN servers
  • Output results with server’'s names, not IP addresses
  • Display fastest servers on top, slowest on bottom

Update: See MattN’s response for a better implementation than mine

This is what I can type in from the command line and it’s served me well so far (using Linux Mint):

 sudo fping -c 5 -ef myserver.txt

where the file “myserver.txt” is the list of VyprVPN servers with the ones I usually use uncommented and the ones I don’t commented:

# Format:
#   Server name
#   Server IP address (commented = skip; uncommented = check)

# Los Angeles, CA

# San Francisco, CA

# etc.....

@RunningWolf We would not be able to assist you with writing a script to accomplish this, but It looks like you’re on to something there for sure. We are planning on adding more features for Linux in the future.

If you do find a working solution for Fastest Server via script, feel free to share it here for other users!

Golden Frog Support

Thanks for the response Nick!

I hope other Linux users might be able to help me improve this, but I also wanted to post it so other users could use it.

Maybe it’s near Christmas, I feel like to throw out some codes :smile: T&Cs: Code quality not guaranteed.

Assuming you have vyprvpn command line client ( and python installed.

Note: the following script does not require sudo or root

  1. Login using vyprvpn command line client first. If you haven’t done so.

    vyprvpn login

  2. Create a python file (e.g. and copy and paste following codes.

    import subprocess as sub
    import re
    import Queue
    import threading

    vyprvpn_bin = ‘/usr/bin/vyprvpn’
    ping_count = 4

    dns_re = r’[\w\d]’
    ping_re = r’min/avg/max/mdev = ([\d.]+)/([\d.]+)/([\d.]+)/([\d.]+) ms’

    def getPingMsAvg(results, dns):
    p = sub.Popen([‘ping’, dns, ‘-c’, str(ping_count)], stdout=sub.PIPE, stderr=sub.PIPE)
    output, errors = p.communicate()
    m =, output, re.M)
    avg_ms = 9999.9
    if m:
    avg_ms = float(
    results.append({ ‘dns’ : dns, ‘ping_avg_ms’ : avg_ms})

    p = sub.Popen([vyprvpn_bin, ‘server’, ‘list’], stdout=sub.PIPE, stderr=sub.PIPE)
    output, errors = p.communicate()

    threads = []
    results = []
    for dns in re.findall(dns_re, output, re.M):
    t = threading.Thread(target=getPingMsAvg, args = (results, dns))

    for t in threads:

    results.sort(cmp=lambda x,y: cmp(x[‘ping_avg_ms’], y[‘ping_avg_ms’]))
    for result in results:
    print “%s: %0.3f ms” % (result[‘dns’], result[‘ping_avg_ms’])

    The following codes set nearest server for you

    nearest_dns = results[0][‘dns’]
    print “Setting nearest server %s as default server” % nearest_dns
    p = sub.Popen([vyprvpn_bin, ‘server’, ‘set’, nearest_dns], stdout=sub.PIPE, stderr=sub.PIPE)
    output, errors = p.communicate()

  3. Run it


  4. Restart VPN connection

    vyprvpn disconnect
    vyprvpn connect

You should get something like this: 17.193 ms 17.524 ms 17.662 ms 130.556 ms 131.514 ms 200.426 ms 202.375 ms 205.899 ms 207.360 ms 235.788 ms 242.700 ms 247.518 ms 247.958 ms 255.425 ms 256.114 ms 258.022 ms 262.761 ms 263.058 ms 263.187 ms 263.555 ms 264.717 ms 264.723 ms 267.139 ms 327.027 ms 333.634 ms 334.134 ms 340.674 ms 342.939 ms 348.427 ms 348.987 ms 349.590 ms 350.341 ms 353.713 ms 355.510 ms 356.644 ms 357.661 ms 357.883 ms 357.946 ms 358.482 ms 359.084 ms 359.249 ms 359.441 ms 360.423 ms 360.669 ms 360.685 ms 364.664 ms
Setting nearest server as default server

Hope this will help you. HoHoHo

1 Like

Hello Matt,

Thank you for the share! We will be happy to check this out, and I’m certain our Linux users looking for fastest server functionality will be excited as well. Happy holidays to you!

Golden Frog Support Supervisor


Worked fine for me.

Merry Xmas!

Same idea using fping and bash:


1. make sure you have fping installed

sudo apt-get install fping

2. make sure you are already logged in

vyprvpn login

vyprvpn disconnect
vyprvpn refresh

TOP5=$(vyprvpn server list | awk ‘{print $1}’ | grep “” | fping -e -c 5 -q 2>&1 | awk -F’[ /]’ ‘{print $16" "$1}’ | sort -n | head -5)
echo “Top 5 Servers”
echo “$TOP5”

vyprvpn server set $(echo $TOP5 | head -1 | awk ‘{print $2}’)
vyprvpn connect

Hello @spraguep,

We appreciate you sharing this, as well as our other Linux users I am sure. We will check this out ourselves, as we continue to look for ways to improve our VyprVPN CLI.

Golden Frog Support

I know this is an old thread but I’ve found this googling. Scrpit came from here. Works wonderful.


add ip / hostname separated by white space



for myHost in $HOSTS
Current1=ping -c 4 -q -i .2 $myHost | grep avg | awk -F'/' '{print $5}'

#echo $myHost $Current
if [ “$Current” -lt “$Smallest” ]
echo “Smallest = $Smallest @ $Server”

I just tried this and after following instructions I received the following:
$ vyprvpn o
Logout result: Logout completed
$ vyprvpn l
Login result: Authorized
$ python
Traceback (most recent call last):
File “”, line 39, in
nearest_dns = results[0][‘dns’]
IndexError: list index out of range
$ vyprvpn c
Success! VyprVPN Connected

So it succeeded, but oddly changed the protocol from Chameleon, which had been my default, to OpenVPN256. The server remained unchanged but the one that was default was almost always the quickest anyway.

I don’t know python. Any ideas?

Hey @sturbs!

I tested Matt’s script just now and experienced different results. It looks like you received some error output, which I wasn’t able to replicate. I suspect it may not have actually worked. Here’s what I did:

  1. Create a new file for the script: touch
  2. Edit the file: nano
  3. Paste the contents of Matt’s script into the file and saved it. (Spacing counts, so needs to be pasted properly)
  4. Logged in: vyprvpn login
  5. Set my protocol to Chameleon: vyprvpn protocol set (4 for Chameleon)
  6. Ran the script: python
  7. It selected mx1, then I connected: vyprvpn c
  8. Checked protocol setting again and verified it was still set to Chameleon: vyprvpn protocol show

Example output:

nickb@ubuntu:~/Desktop$ vyprvpn protocol set
VyprVPN Protocols
1: pptp
2: openvpn160
3: openvpn256
4: chameleon
Please enter the number of your selection:
Success: chameleon set as new default
nickb@ubuntu:~/Desktop$ python


Setting nearest server as default server
nickb@ubuntu:~/Desktop$ vyprvpn c
Success! VyprVPN Connected
nickb@ubuntu:~/Desktop$ vyprvpn protocol show

Just wanted to share my experience. Perhaps try remaking the file and running the script again. Let me know if you have success. FYI - I am a Python noob myself, but in looking at the script, I am not seeing anything that sets the preferred protocol.

Golden Frog Support

For users not so used to linux
Useful bash script for fast connecting if you are always going to want to connect to same server.
Have hashed out the password parts as bad practice to keep passwords in plain text.

Customise as you please i know I’m in the UK so that will most of the time be the sever I want to connect to.
Save the following to a .sh file can be any name you like.

vyprvpn l $email #$password
vyprvpn server set $server
vyprvpn protocol set $protocol
vyprvpn connect

Once you create a file need to set it to executable
chmod +x

run it with the following

Have added protocol as a variable in hope they add more

I know its nothing fancy but hopefully will save someone time who wants something quick and simple

Thanks for taking the time to post this script here! I’ll bet other users will find this useful.