Skip to content

Instantly share code, notes, and snippets.

@jailbirt
Last active November 20, 2019 22:05
Show Gist options
  • Save jailbirt/9b2bbfbcf1ce5da13d26286cef739d85 to your computer and use it in GitHub Desktop.
Save jailbirt/9b2bbfbcf1ce5da13d26286cef739d85 to your computer and use it in GitHub Desktop.
For every time this script is invoqued It changes the server IP by using nordvpn. It install all the necesary packages only tested on ubuntu 18.04
#!/bin/bash
#If you are running on AWS add this route tables before running this script, otherwise you won't be able to do a ssh login.
#A good place is user-data before running the instance
#ip rule add from $(ip route get 1 | grep -Po '(?<=src )(\S+)') table 128
#ip route add table 128 to $(ip route get 1 | grep -Po '(?<=src )(\S+)')/32 dev $(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
#ip route add table 128 default via $(ip -4 route ls | grep default | grep -Po '(?<=via )(\S+)')
user=$1
pass=$2
if whoami | grep -v root;then echo "failure run as root";exit;fi
if [ ! -f /etc/openvpn/auth.txt ];then
echo "Installing"
#url:https://ucp.nordvpn.com/login/
#PROVISIONING#
apt-get update
apt-get install -y openvpn openvpn-systemd-resolved ca-certificates unzip
echo "$user">/etc/openvpn/auth.txt
echo "$pass">>/etc/openvpn/auth.txt
cd /etc/openvpn || exit
wget https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip
unzip ovpn.zip
rm ovpn.zip
#add auto-login for each file.
find ./ovpn_* -iname "*ovpn" -exec sed -i "s:auth-user-pass:auth-user-pass /etc/openvpn/auth.txt:g" {} \;
for config in $(ls /etc/openvpn/ovpn_*/*); do
echo "script-security 2
up /etc/openvpn/update-systemd-resolved
down /etc/openvpn/update-systemd-resolved
down-pre
dhcp-option DOMAIN-ROUTE ." >> $config
done
fi
pkill -f openvpn
openvpnLog=/var/log/openvpn.log
echo "" > $openvpnLog
currentIP=$(curl -s https://ipinfo.io/ip)
configPath="/etc/openvpn/ovpn_tcp"
#iterate for all AR ips. for i in /etc/openvpn/ovpn_tcp/ar*
#pick one ip random
configFile=$configPath/$(ls /etc/openvpn/ovpn_tcp/ | shuf -n 1 )
date
openvpn --config "$configFile" --daemon --log $openvpnLog
while ! grep "Initialization Sequence Completed" $openvpnLog > /dev/null; do
echo "current IP is:$currentIP waiting for vpn connection"
sleep 1
done
currentIP=$(curl -s https://ipinfo.io/ip)
echo "IP change to $currentIP"
service theeye-agent restart
date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment