Viktor Jaep
Part of the Furniture
v2.0 - Now with even more SuperRandom(tm) goodness!!
Updated July 10 2022
Executive Summary: VPNMON-R2 v2.0 (VPNMON-R2.SH) is an all-in-one script that works for any VPN service of your choice, but is optimized for NordVPN, SurfShark VPN and Perfect Privacy VPN services. It can also compliment @JackYaz's VPNMGR program to maintain a NordVPN/PIA/WeVPN setup. This script will check the health of (up to) 5 VPN connections on a regular interval to see if one is connected, and sends a ping to a host of your choice through the active connection. If it finds that connection has been lost, it will execute a series of commands that will kill all VPN clients, will optionally whitelist all NordVPN/PerfectPrivacy VPN servers in the Skynet Firewall, and randomly picks one of your (up to) 5 VPN Clients to connect to. One of VPNMON-R2's unique features is called "SuperRandom", where it will randomly assign VPN endpoints for a random county (or your choice) to your VPN slots, and randomly connect to one of these. It will now also test your WAN connection, and put itself into standby until the WAN is restored before reconnecting your VPN connections. Major features: Now included in AMTM, Fastest Connection Switching, Perfect Privacy/SurfShark/NordVPN VPN Compatible, WAN Awareness, YazFi Compatible, Multi-Country Capable.
VPNMON is free to use under the GNU General Public License version 3 (GPL 3.0).
This project is hosted on GitHub
Changelog here / What's new: VPNON Sunset/Integration and more -- VPNMON-R2 is now available in AMTM!
Screenshot:
Updated July 10 2022
Executive Summary: VPNMON-R2 v2.0 (VPNMON-R2.SH) is an all-in-one script that works for any VPN service of your choice, but is optimized for NordVPN, SurfShark VPN and Perfect Privacy VPN services. It can also compliment @JackYaz's VPNMGR program to maintain a NordVPN/PIA/WeVPN setup. This script will check the health of (up to) 5 VPN connections on a regular interval to see if one is connected, and sends a ping to a host of your choice through the active connection. If it finds that connection has been lost, it will execute a series of commands that will kill all VPN clients, will optionally whitelist all NordVPN/PerfectPrivacy VPN servers in the Skynet Firewall, and randomly picks one of your (up to) 5 VPN Clients to connect to. One of VPNMON-R2's unique features is called "SuperRandom", where it will randomly assign VPN endpoints for a random county (or your choice) to your VPN slots, and randomly connect to one of these. It will now also test your WAN connection, and put itself into standby until the WAN is restored before reconnecting your VPN connections. Major features: Now included in AMTM, Fastest Connection Switching, Perfect Privacy/SurfShark/NordVPN VPN Compatible, WAN Awareness, YazFi Compatible, Multi-Country Capable.
VPNMON is free to use under the GNU General Public License version 3 (GPL 3.0).
This project is hosted on GitHub
Changelog here / What's new: VPNON Sunset/Integration and more -- VPNMON-R2 is now available in AMTM!
Screenshot:
The Problem I was trying to solve
- As a former VPNMGR user, I had 5 different NordVPN VPN Client configurations populated on my Asus router running Merlin FW, each with a different city. There were times that I would lose connection to one of these servers, and the router would just endlessly keep trying to reconnect to no avail. Also, sometimes the SKynet firewall would block these NordVPN endpoints, and it would again, endlessly try to connect to a blocked endpoint. Other times, freakishly, I would have more than 1 VPN Client kick on for some reason. This program was built as a way to check to make sure VPN is connected, that the connection is clean, and that there aren't multiple instances running. If anything was off, it would launch a full-on assault and try to reset everything back to a normal state.
- I also wanted a way for my VPN connection to reset each night, so that it would randomly select and connect to a different configuration, thus endpoint, so that I wouldn't be connected to the same city 24x7x365.
- NordVPN literally has thousands of VPN endpoint servers which change frequently, depending on the distance or latency from your location scattered across the globe. On several occations, my Asus-Merlin-based Skynet firewall would block these VPN servers, and wanted to make sure I had a way to find all the latest VPN server IPs, and add them to the Skynet whitelist.
- Above all, I wanted to make this script flexible enough for those who aren't running VPNMGR, using NordVPN or making use of the Skynet Firewall, so options have been built-in to bypass this functionality to make it usable in any VPN usage scenario.
How is this script supposed to run?
Personally, I run this script in its own SSH window from a PC that's connected directly to the Asus router, as it loops and checks the connection every 60 seconds. Instructions:- Download and install directly from AMTM, or using your favorite SSH tools, copy & paste this command:
Code:
curl --retry 3 "https://raw.githubusercontent.com/ViktorJp/VPNMON-R2/master/vpnmon-r2-2.0.sh" -o "/jffs/scripts/vpnmon-r2.sh" && chmod a+rx "/jffs/scripts/vpnmon-r2.sh"
- To initially configure this script, open up a dedicated SSH window, and simply execute the script::
Code:
sh /jffs/scripts/vpnmon-r2.sh -setup
- Once you've successfully configured the various options, you can run the script using this command:
Code:
sh /jffs/scripts/vpnmon-r2.sh -monitor
- First, make sure you install the "screen" utility (and have Entware installed):
Code:
opkg install screen
- The screen utility allows you to run the script in the background, detached from your current ssh session. Type:
Code:
screen -dmS vpnmon-r2 sh /jffs/scripts/vpnmon-r2.sh -monitor
- You can then reattach to the running script at any time, from any ssh session, on any client machine! Type:
Code:
screen -r vpnmon-r2
- Perform the detach by hitting CTRL-A + D
- To make it easier, can now also just execute VPNMON-R2 with the -screen switch. Type:
Code:
sh vpnmon-r2.sh -screen
What this script does
- Checks the VPN State from NVRAM and determines if each of the 5 Clients are connected or not
- If a VPN Client is connected, it sends a PING through to Google's DNS server to determine if the link is good (configurable)
- If it determines that the VPN Client is down, or connection is broken, it will attempt to reset the VPN
- If it determines that multiple VPN Clients are running, it will attempt to reset the VPN
- If it determines that the NordVPN server load is too high (optional), it will attempt to reset the VPN
- Updates Skynet whitelist with all US-based NordVPN endpoint IP addresses (optional) - FYI, you can easily change this for the country of your choice.
- Updates vpnmgr cache with recommended NordVPN/PIA/WeVPN endpoint information (optional), and merges/refreshes these changes with your VPN Client configurations
- Uses a randomizer to pick one of 5 different VPN Clients to connect to (configurable between 1 and 5)
- It will loop through this process every 60 seconds (configurable)
- If it determines that my other (optional) external script VPNON.SH is resetting the connection, it will hang back until it's done.
- Logs major events (resets/connection errors/etc) to a log file.
- It will reset your VPN connection at a regularly scheduled time using the settings at the top of the script (optional)
- It now shows the last time a VPN reset happened indicated by "Last Reset:", an indicator when the next reset will happen, and how often the interval happens (in seconds) on the easy-to-read VPNMON-R2 interface in your SSH shell, along with a progressbar to show script activity
- Added a new API lookup to display the VPN exit node city/location next to the active VPN connection. This API is free, and guarantees at least 1000 lookups per month. In lieu of doing a lookup each single refresh interval, a location lookup is only done when either the script starts up fresh, when it detects VPNON doing a reset, or if VPNMON-R2 initiates a reset.
- Added the concept of SuperRandom(tm) NordVPN Connections! This is a NordVPN/SurfShark/PerfectPrivacy feature only! When enabled, it will fill your VPN client slots with random VPN servers across the country of your choice. Distance, load, and performance be damned!!
- Added an integrated configuration utility (by running "vpnmon-r2.sh -config") that steps you through all the options and saves results to a config file, without the need to manually edit and configure the script itself.
- Added a script update checker, which notifies you when a new version becomes available, and allows you to easily download an install the latest script by using the 'vpnmon-r2.sh -update' command.
- Optionally shows a row of stats on bottom row, indicating low/high ping times, NordVPN server load, Avg sent/received bandwidth (in Mbps), and total traffic sent/received on the active tunnel.
- Added the ability to specify up to 2 additional NordVPN countries (for a total of 3) to randomly pick VPN servers located within that country. Yes, we have gone completely international!
- Happy to report that VPNMON-R2 now integrates beautifully with YazFi - the premier expanded guest network utility for Merlin firmware! For those running multiple guest networks, VPNMON-R2 can now automatically update your guest network slots with the latest VPN slot that VPNMON-R2 just made a connection to, then performs the necessary steps to make YazFi acknowledge the change to ensure your guest client devices continue to work without interruption!
- Added capabilities to check if your modem goes down, or your ISP stops working, then falls back and waits until your WAN comes back up in order to re-establish a VPN connection.
- VPNMON-R2 is now compatible with Perfect Privacy and SurfShark VPN services!
- Added capabilities to switch to the fastest connections based on ping ms to your VPN endpoints.
- Happy to announce that VPNMON-R2 is now being included in AMTM! Many thanks to @thelonelycoder!
Last edited: