Last active
January 3, 2023 21:39
-
-
Save jailbirt/274b337fb7ce4b8cbab6dfbccccc0d33 to your computer and use it in GitHub Desktop.
It connects to nordvpn for a given country, and leaves ssh connection working from the internet. It works pretty well with aws ec2 instances.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Only tested on ubuntu 22.04. | |
#It requires openvpn installed with its ca certificates. | |
#If you are running it from AWS please set up your aws ec2 instance to allow traffic from different networks. | |
# on your EC2 instance at the EC2 Dashboard -> Actions -> Networking -> Change source/destination check -> And allow all traffic. | |
## Config | |
#set your country [a-z][a-z] | |
country="ar" | |
#set your country name, check this at ipinfo.io | |
contryName="Argentina" | |
log="/tmp/1.log" | |
passFile="/home/ubuntu/pass.txt" | |
## End | |
if [ $(whoami) != "root" ] ; then | |
echo error run as root | |
exit 1 | |
fi | |
#update nordvpn servers. | |
cd /etc/openvpn | |
rm -rf ovpn* | |
wget https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip | |
unzip ovpn.zip | |
echo "Verify logs at $log" | |
minServer=$(ls /etc/openvpn/ovpn_udp/|grep ar[0-9][0-9].nordvpn|cut -d . -f 1|sed s/$country//g|head -n1) | |
maxServer=$(ls /etc/openvpn/ovpn_udp/|grep ar[0-9][0-9].nordvpn|cut -d . -f 1|sed s/$country//g|tail -n1) | |
while : ; do | |
service theeye-agent stop | |
pkill -9 -f openvpn | |
echo "ip route before"&> $log | |
curl --silent ipinfo.io &>> $log | |
ip route show | grep default &>> $log | |
echo "connecting to $minServer" &>> $log | |
sudo -b openvpn --config /etc/openvpn/ovpn_udp/ar$minServer.nordvpn.com.udp.ovpn --auth-user-pass $passFile | |
thisDefaultGW=172.31.80.1 | |
network="172.31.0.0/16" | |
ip route add $network via $thisDefaultGW dev eth0 | |
sleep 20 | |
echo "Testing vpn connection" >> $log | |
curl --silent ipinfo.io &>> $log | |
ip route show | grep default &>> $log | |
minServer=$((minServer + 1)) | |
if curl -s ipinfo.io |grep $contryName | |
then | |
echo "conected from $countrName!" | |
service theeye-agent start | |
break | |
fi | |
if [ "$minServer" -ge "$maxServer" ] | |
then | |
echo "No servers available left" | |
service theeye-agent start | |
pkill -9 -f openvpn | |
break | |
fi | |
echo "trying next server $minServer" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment