NordVPN easy_script connection

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Advanced Networking
Goto page 1, 2  Next
Author Message
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Sat Jun 01, 2019 19:47    Post subject: NordVPN easy_script connection Reply with quote
Hi to all.

First of all I want to say that I'm not a professional programmer, so, maybe this little script is not perfect and can be improved, so if you find some that not work so good or you've a better idea method, you're welcome to tell me what is wrong!

So, this script basically:
1. For each country you select, search the top server and pick the best one!
2. Start a watchdog for vpn interface, that check every 60 sec if the vpn is up and running.
3. Start a watchdog for server load, if the current load is over a threshold, change it.

So, let's better see what you need to run this script:
-> Entware https://wiki.dd-wrt.com/wiki/index.php/Installing_Entware
-> jq (opkg install jq)

How install it?
Simply copy the script to your preferred place, I prefer copy it to /opt/bin and make it executable with chmod ugo+x /opt/bin/easy_nordvpn

How can I run the script?
I usually have one script that I call at boot, so I prefer use an intermediate script to do all the dirty works, and from the Administration -> Commands -> Startup I call it, so in my case inside the Startup field I've /opt/startup_script.sh and inside the startup_script.sh I've sleep 30 && /opt/bin/easy_nordvpn start
So at the end you've to put sleep 30 && /opt/bin/easy_nordvpn start in your startup

Now you've to configure your vpn client like always, go to Services -> VPN -> OpenVPN Client and configure the client like NordVPN suggest.

The very next step is to configure the script, is quite easy, you've to configure only few option, are all inside the easy_nordvpn script, so just nano or vi the script. The most important configutation is:
Code:
# Specify, comma separated, the country you want to connect from vpn, can be more than one.
# Just remember that must be the contry number, like 106 for Italy, or "228,202" for US and Spain at the same time
COUNTRYSELECTION_ID=""

Then
Code:
# Max load is usded to check the actual server load, if the load go over the MAX_LOAD, the script will change the vpn server.
# Don't select a too lower value, in this case the script will always change the server
MAX_LOAD=35

You can look inside the script to see other options, normally the value inserted are quite good, but you can change it if you need it.

So now you can reboot your router or just start the script via ssh with easy_nordvpn start

What I can do with the script?
Here a list of commands:

Code:
easy_nordvpn start -> This must be used only at boot, so don't use it if you don't know what're you doing

easy_nordvpn stop -> This stop the script execution

easy_nordvpn restart -> This will restart the entire script

easy_nordvpn status -> This check the actual status of vpn, actually check if connected and current server with load

easy_nordvpn force_connection -> This force a new connection, so if you use it the script connect to first best server.

easy_nordvpn interface_check -> This check only the VPN_INTERFACE, in order to check if is up and working

easy_nordvpn checkload -> This check the current server load, if is too low, make a new connection.
(note that the script connect to the new best server, but maybe this server already have higher load so at the next check the script will change again, and so on)


I want to thank egc for the infinite patience!

For now is all, if you've any question please ask, I would try to do my best to change possible errors.

Jo


Last edited by Chryses on Tue Jun 18, 2019 5:02; edited 5 times in total
Sponsor
Robbin95
DD-WRT Novice


Joined: 03 Jun 2019
Posts: 10

PostPosted: Mon Jun 03, 2019 13:49    Post subject: Reply with quote
Hi!

First of all, thanks for creating this script!!
However, I'm having great struggles installing JQ.
I have no idea what it is and I can't figure out how to install it correctly.

PuTTY is currently displaying the next message:
Starting vpn script ...

easy_nordvpn is restarting ... please wait

Starting from scratch ...
Removing scripts

Taking down OpenVPN Client Routes

Shutting Down OpenVPN...

Restarting dnsmask service


Starting from scratch ...
Vpn connection script called
Let's see if all is good to start ...
Jq bin not found, I can't work without it, please install it and try again!!!

Vpn script finished

--------------------

What is JQ and how can I install it properly?

Thanks in advance
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Mon Jun 03, 2019 16:36    Post subject: Reply with quote
Hi Robbin.

jq is an Entware package, so in order to install it, first you've to install Entware https://wiki.dd-wrt.com/wiki/index.php/Installing_Entware
Then you can install jq and run the script
Robbin95
DD-WRT Novice


Joined: 03 Jun 2019
Posts: 10

PostPosted: Mon Jun 03, 2019 19:35    Post subject: Reply with quote
I just can't get Entware installed. Tried everything. This is the best result I got:

wget -O - http://pkg.entware.net/binaries/mipsel/installer/in
staller.sh | sh
Connecting to pkg.entware.net (104.27.176.50:80)
Info: Creating folders...
Info: Deploying opkg package manager...
Downloading /opt/bin/opkg... success!
Downloading /opt/etc/opkg.conf... success!
Downloading /opt/etc/profile... success!
Downloading /opt/etc/init.d/rc.func... success!
Downloading /opt/etc/init.d/rc.unslung... success!
Info: Basic packages installation...
Downloading http://pkg.entware.net/binaries/mipsel/Packages.gz
Updated list of available packages in /opt/var/opkg-lists/entware-ng
Installing ldconfig (1.0.17-1) to root...
Downloading http://pkg.entware.net/binaries/mipsel/ldconfig_1.0.17-1_mipselsf.ip k
Installing findutils (4.6.0-1) to root...
Downloading http://pkg.entware.net/binaries/mipsel/findutils_4.6.0-1_mipselsf.ip k
Installing libc (1.0.17-1) to root...
Downloading http://pkg.entware.net/binaries/mipsel/libc_1.0.17-1_mipselsf.ipk
Installing libgcc (5.4.0-1) to root...
Downloading http://pkg.entware.net/binaries/mipsel/libgcc_5.4.0-1_mipselsf.ipk
Installing libssp (5.4.0-1) to root...
Downloading http://pkg.entware.net/binaries/mipsel/libssp_5.4.0-1_mipselsf.ipk
Configuring ldconfig.
Configuring libgcc.
Configuring libc.
Configuring libssp.
Configuring findutils.
Collected errors:
* extract_archive: Cannot create symlink from ./opt/lib/ld-uClibc.so.0 to 'ld-u Clibc.so.1': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/ld-uClibc.so.1 to 'ld-u Clibc-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libc.so.0 to 'libuClibc -1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libc.so.1 to 'libuClibc -1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libcrypt.so to 'libcryp t.so.1': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libcrypt.so.0 to 'libcr ypt-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libcrypt.so.1 to 'libcr ypt-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libdl.so to 'libdl.so.1 ': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libdl.so.0 to 'libdl-1. 0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libdl.so.1 to 'libdl-1. 0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libm.so to 'libm.so.1': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libm.so.0 to 'libm-1.0. 17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libm.so.1 to 'libm-1.0. 17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libnsl.so to 'libnsl.so .1': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libnsl.so.0 to 'libnsl- 1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libnsl.so.1 to 'libnsl- 1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libresolv.so to 'libres olv.so.1': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libresolv.so.0 to 'libr esolv-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libresolv.so.1 to 'libr esolv-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libuargp.so to 'libuarg p.so.1': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libuargp.so.1 to 'libua rgp-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libutil.so to 'libutil. so.1': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libutil.so.0 to 'libuti l-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libutil.so.1 to 'libuti l-1.0.17.so': Operation not permitted.
* extract_archive: Cannot create symlink from ./opt/lib/libssp.so.0 to 'libssp. so.0.0.0': Operation not permitted.
ln: /opt/etc/TZ: Operation not permitted

Congratulations! If there are no errors above then Entware-ng is successfully in itialized.

Found a Bug? Please report at https://github.com/Entware-ng/Entware-ng/issues

Type 'opkg install <pkg_name>' to install necessary package.
---------

I'm running dd-wrt on a Netgear WNR3500Lv2 behind another router (Netgear WNR2000V2) which is connected to the modem. My PC is running Windows.

Any ideas?
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Mon Jun 03, 2019 19:50    Post subject: Reply with quote
The only thing I can ask is: have you created and mounted the usb?
Robbin95
DD-WRT Novice


Joined: 03 Jun 2019
Posts: 10

PostPosted: Mon Jun 03, 2019 19:56    Post subject: Reply with quote
[img]https://ibb.co/bJwNGTy[/img]
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Mon Jun 03, 2019 20:08    Post subject: Reply with quote
I see your usb is fat32, that is not good for symlink.
Better see the Preparation phase on https://wiki.dd-wrt.com/wiki/index.php?title=Installing_Entware

I think all your problem is here.
Robbin95
DD-WRT Novice


Joined: 03 Jun 2019
Posts: 10

PostPosted: Mon Jun 03, 2019 20:43    Post subject: Reply with quote
Thanks for the quick reply!
I understood the issue and fixed it!
But... Even after installing JQ...:

easy_nordvpn restart
=================================
Starting vpn script ...

easy_nordvpn is restarting ... please wait

Starting from scratch ...
Removing scripts

Taking down OpenVPN Client Routes

Shutting Down OpenVPN...

Restarting dnsmask service


Starting from scratch ...
Vpn connection script called
Let's see if all is good to start ...
Ready to establish a new vpn connection
Selecting and making server configuration files
/opt/bin/easy_nordvpn: line 376: jq: Permission denied
Someting goes wrong during server selection, better restart all.
la variabile è:

Vpn script finished
=================================
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Tue Jun 04, 2019 4:12    Post subject: Reply with quote
Can you paste the configuration line of the script? So I can try with your configuration combination
Robbin95
DD-WRT Novice


Joined: 03 Jun 2019
Posts: 10

PostPosted: Tue Jun 04, 2019 10:53    Post subject: Reply with quote
#!/bin/sh

############## CONFIGURATIONS ##############
# Specify, comma separated, the country you want to connect from vpn, can be more than one.
# Just remember that must be the contry number, like 106 for Italy, or "228,202" for US and Spain at the same time
COUNTRYSELECTION_ID="228"

# Here you've to select the Server Technology, only one can be used!
# Server technology -> ID
# OpenVPN UDP -> 3
# OpenVPN TCP -> 5
SERVER_TECHNOLOGIES_ID=3

# Here you've to select the Server group, only one can be used!
# Server group -> ID
# Double VPN -> 1
# Onion over VPN -> 3
# Dedicated IP -> 9
# Standard VPN -> 11
# P2P -> 15
SERVER_GROUP=15

# How many server you want to query? With 10 you'll ask for the top 10 server for each country, then the script will select the best one.
MAX_QUERY_SERVERS=10

# Max load is usded to check the actual server load, if the load go over the MAX_LOAD, the script will change the vpn server.
# Don't select a too lower value, in this case the script will always change the server
MAX_LOAD=35

# Which interface for the vpn?
VPN_INTERFACE="tun1"

# Which server do you want to ping?
PING_SERVER=8.8.8.8

# Openvpn client configuration directory?
OVPNCLIENTFOLDER="/tmp/openvpncl"

# Interface check watchdog - time till checks (value rappresent seconds) If value greather than 0 the script will generate a watchdog script that run every X seconds
INTERFACE_CHECK_WATCHDOG_DELAY=60

# Interface check watchdog - time till checks (value rappresent seconds) If value greather than 0 the script will generate a watchdog script that run every X seconds
LOAD_CHECK_WATCHDOG_DELAY=3600

# Create a log file? 1 to enable (normally is only for debug purpose)
ENABLELOG="0"
############## CONFIGURATIONS ##############

I just changed (as far as I know) the countryselection to use the US servers.
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Tue Jun 04, 2019 19:30    Post subject: Reply with quote
Bizarre!

Can you give me the output of this?
Code:
curl -ks "https://api.nordvpn.com/v1/servers/recommendations?filters\[servers_groups\]=15&filters\[servers_technologies\]=3&filters\[country_id\]=228&limit=10" | jq --raw-output --slurp ' .[] | sort_by(.load) | .[] | [.hostname, .load] | "\(.[1]):\(.[0])"'


And
Code:
free


And
Code:
df -h


And please try to change
Code:
MAX_QUERY_SERVERS=10
to
MAX_QUERY_SERVERS=3


Can be a memory problem, maybe 10 servers is too much to store in memory (in fact I alredy ask the best servers, so in theory I can ask only 1 server)

Maybe the var selection is not the best, but on my side works, so we've to find why don't works on your side
Robbin95
DD-WRT Novice


Joined: 03 Jun 2019
Posts: 10

PostPosted: Tue Jun 04, 2019 21:49    Post subject: Reply with quote
Code curl:

curl -ks "https://api.nordvpn.com/v1/servers/recommendations?
filters\[servers_groups\]=15&filters\[servers_technologies\]=3&filters\[country_
id\]=228&limit=10" | jq --raw-output --slurp ' .[] | sort_by(.load) | .[] | [.ho
stname, .load] | "\(.[1]):\(.[0])"'
-sh: jq: Permission denied

----------

Code free:

free
total used free shared buffers cached
Mem: 125724 46328 79396 0 5568 15356
-/+ buffers/cache: 25404 100320
Swap: 0 0 0

----------

Code df -h:

df -h
Filesystem Size Used Available Use% Mounted on
rootfs 25.4M 25.4M 0 100% /
/dev/root 25.4M 25.4M 0 100% /
none 512.0K 0 512.0K 0% /dev
/dev/sda1 3.6G 9.4M 3.4G 0% /opt
/dev/sda1 3.6G 9.4M 3.4G 0% /tmp/mnt/sda1

----------

Changing the query didn't do the trick...
Thanks for the help!


Last edited by Robbin95 on Tue Jun 04, 2019 22:07; edited 1 time in total
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Tue Jun 04, 2019 22:05    Post subject: Reply with quote
Mmm. I suspect that you're not with root privilege.

Let me guess, you run the ssh connection from winscp?

In theory the script will start after a reboot, if you put the autostart line
So you can try to reboot the router and see if works.

But if you want to try by hand via ssh connection you've to be root, so use putty to connect and use root user (obviously I'm thinking that you're not root, maybe I'm wrong)

I've to investigate why there's permission denied error

PS try to
chmod 777 pathtonordvpn script file
Maybe the permission is wrong
Robbin95
DD-WRT Novice


Joined: 03 Jun 2019
Posts: 10

PostPosted: Tue Jun 04, 2019 22:08    Post subject: Reply with quote
I'm running these in PuTTY (username=root)!
I've tried a lot of things. Trust me, already rebooted over 50 times...
Chryses
DD-WRT User


Joined: 27 Jun 2018
Posts: 99

PostPosted: Tue Jun 04, 2019 22:10    Post subject: Reply with quote
PS try to
chmod 777 pathtonordvpn script file
Maybe the permission is wrong
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum