Skip to content

Instantly share code, notes, and snippets.

@junderw
Created December 29, 2018 16:11
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 junderw/10bee41c45ee68771e428e3599088000 to your computer and use it in GitHub Desktop.
Save junderw/10bee41c45ee68771e428e3599088000 to your computer and use it in GitHub Desktop.
NordVPN: JPN or USA to connect to the country you want.
#!/bin/bash
SELECTION=$1
if [ -z "$1" ]
then
SELECTION="JPN"
fi
# Default JPN
CODE=108
if [[ $SELECTION == "JPN" ]]
then
CODE=108
fi
if [[ $SELECTION == "USA" ]]
then
CODE=228
fi
# The base URL for getting suggestion for the best server for a country
BASEURL=https://nordvpn.com/wp-admin/admin-ajax.php
QUERY1=action=servers_recommendations
QUERY2HEAD=filters={'"'country_id'"':
SERVER=`curl -sG $BASEURL -d $QUERY1 -d $QUERY2HEAD$CODE} | jq -r '.[0]["hostname"]'`
# Create a temp folder in /tmp
TMPFOLDER=$(mktemp -d)
cd $TMPFOLDER
# Download nordvpn server config files and unzip them, then cd into them
wget https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip &>/dev/null
unzip ovpn.zip &>/dev/null
cd ovpn_udp
# Run openvpn
sudo openvpn $SERVER.udp.ovpn
# Clean up after openvpn exits
rm -rf $TMPFOLDER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment