Skip to content

Instantly share code, notes, and snippets.

@JonCooperWorks
Created August 3, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonCooperWorks/ca0108288c269977e93b to your computer and use it in GitHub Desktop.
Save JonCooperWorks/ca0108288c269977e93b to your computer and use it in GitHub Desktop.
Automatically connect to a random VPN upon connecting to a network. Tested on Fedora 22
#!/bin/bash
VPN_NAME=""
i=0
VPN_COUNT=5
random=$RANDOM
for name in "Germany" "USA" "Canada" "Netherlands" "Sweden"
do
if (( random % VPN_COUNT == ++i )); then
VPN_NAME=$name
fi
done
status=$2
case $status in
up|vpn-down)
nmcli con up id "$VPN_NAME"
;;
down)
if nmcli con status id "$VPN_NAME" | grep -qs activated; then
nmcli con down id "$VPN_NAME"
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment