Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Rotate between different NordVPN servers with ease. Works both on Linux and Windows without any required changes to your code!
(11/06/2022)
Updates for version 0.3.0:
Updates for version 0.2.9:
Updates for version 0.2.8:
Updates for version 0.2.7:
Updates for version 0.2.6:
Updates for version 0.2.5:
Added a 'complete rotation' functionality: allows you to rotate between the 4000+ available servers at random. This is different from connecting to a specific region (e.g. country, state), since NordVPN automatically opts for the 'best' server in that particular area. This means you're often connecting to the same small subset of fast servers. When the 'complete rotation' parameter is set to 1, server rotation is truly random. This is a neat function for webscraping purposes.
Added a 'skip settings' functionality (for Linux users only): Linux users are asked whether they'd like to execute additional settings (such as whitelisting ports) whenever they run the initialize_VPN() function. When the skip_settings parameter is set to 1, nordvpn-switcher will assume the user does not wish to execute additional settings. When the user combines this with the area_input parameter, it is possible to run NordVPN switcher right from the get-go without any required user-input on Linux (see demo.py for example code).
The script uses the fake_useragent package for improved header-input
Added an additional pause to slow the script down on Windows. Some users - especially if they run the NordVPN app on slow machines - are unable to rotate between servers because the app takes a while to start up.
Added more example code in the demo.py file (see files on Github)
To all of those who've sent me feedback and/or reported bugs: thank you!
Rotate between different NordVPN servers with ease. Works both on Linux and Windows without any required changes to your code.
pip install nordvpn-switcher
and you're all set!
Created by Kristof Boghe
I realize there are multiple NordVPN-related packages available, but they only work for Linux and/or are not exactly user-friendly.
NordVPN-switcher is:
1. Able to run both on Windows and Linux
2. User-friendly
save
parameter to 1).3. Forgiving
4. Able to check for captcha's on Google and/or YouTube
google_check
parameter to 1), captcha-checks are performed after each server rotation. If a captcha pops up, the script will automatically try a new server.5. Flexible
wget -qnc https://repo.nordvpn.com/deb/nordvpn/debian/pool/main/nordvpn-release_1.0.0_all.deb
sudo dpkg -i /pathToFile/nordvpn-release_1.0.0_all.deb #replace pathToFile to location download folder
sudo apt update
sudo apt install nordvpn
(From the NordVPN FAQ)
Download the app here --> https://bit.ly/3ig2lU5
pip install nordvpn-switcher
OR, for the ones who don't use pip for some reason:
pip install -r requirements.txt
to install dependenciesImport functions`from nordvpn_switcher import initialize_VPN,rotate_VPN,terminate_VPN
Rotate between servers, for example:
import time
initialize_VPN(save=1,area_input=['complete rotation'])
for i in range(3):
rotate_VPN()
print('\nDo whatever you want here (e.g.scraping). Pausing for 10 seconds...\n')
time.sleep(10)
will perform a truly random rotation between all available NordVPN servers.
That's it!
1. Setting up your NordVPN settings
['complete rotation']
. If you'd like to rotate between 10 random European countries, set this parameter to ['random countries europe 10']
etc. See the demo.py file for more examples.initialize_VPN(stored_settings=0,save=0,area_input=None,skip_settings=None)
2. Rotating between servers.
save
parameter in the first function to 1).rotate_VPN(instructions=None,google_check = 0)
3. Disconnecting from the VPN service
terminate_VPN(instructions=None)
--> Please check out the demo.py file on GitHub (https://github.com/kboghe/NordVPN-switcher/) for more examples <--
Option 1: save settings in environment The easiest and most user-friendly (although least automated) way of using NordVPN switcher is by saving the instructions into a new variable and feeding it to the rotate_VPN() function.
from nordvpn_switcher import initialize_VPN,rotate_VPN,terminate_VPN
settings = initialize_VPN()
rotate_VPN(settings)
rotate_VPN(settings,google_check=1)
terminate_VPN(settings)
In practice, you'll usually execute the rotate_VPN() function within some kind of loop.
settings = initialize_VPN() #initialize VPN and save settings variable
for i in range(3): (e.g. you'd like to loop over 10.000 urls)
rotate_VPN(settings)
*perform some other code, e.g. scraping*
rotate_VPN(settings,google_check=1) #with google and youtube captcha check
terminate_VPN(settings)
if you want to rotate between servers in an infinite loop, you can use the while true statement:
while True:
rotate_VPN(settings)
time.sleep(3600) #e.g. rotate servers every hour
Thanks to the area_input parameter and the 'complete rotation' functionality, you don't have to provide any input at all. NordVPN will simply hop from server to server in a truly random fashion.
initialize_VPN(save=1,area_input=['complete rotation'])
for i in range(3):
rotate_VPN()
*perform some other code, e.g. scraping*
terminate_VPN()
Option 2: save settings and execute on each run
If you want to make sure that certain NordVPN setting commands are executed (e.g. killswitch, whitelisting ports, etc.) on each run, save the instructions into your project folder once by setting the save
parameter to 1 and execute the initialize_VPN
and rotate_VPN
function every time you run the script. NordVPN-switcher will alert you what kind of additional settings are pulled from the settings-file.
#do this once
initialize_VPN(save=1)
If save=1
, the script will write a .txt file in JSON format to your project folder. It contains all the necessary information needed to execute the rotate_VPN
function. Again, when the instructions parameter is missing in rotate_VPN
, it will automatically look for the settings file in your project folder.
--On Windows, the contents of the nordvpn_settings.txt file look something like this (random example):
`{'opsys': 'Windows', 'command': ['nordvpn', '-c', '-g'], 'settings': ['belgium', 'netherlands', 'germany', 'spain', 'france'], 'original_ip': '82.169.108.182', 'cwd_path': 'C:/Program Files/NordVPN'}
-- On Linux, the file looks slightly different (different random example):
{'opsys': 'Linux','original_ip': '82.169.108.182','command': ['nordvpn', 'c'], 'settings': ['United_States', 'Canada', 'Brazil', 'Argentina', 'Mexico', 'Chile', 'Costa_Rica', 'Australia'], 'additional_settings': [['nordvpn', 'set', 'killswitch', 'disable'], ['nordvpn', 'whitelist', 'add', 'port', '23']],'credentials':[['name@gmail.com'],['coolpassword]]}
Thanks to the saved .txt file, you never need to go through the menu options of initialize_VPN()
again. So, some time later, you simply perform:
initialize_VPN(stored_settings=1)
rotate_VPN()
#do stuff
terminate_VPN()
This option is only relevant for Linux users who wish to execute additional settings such as enabling killswitch etc. Executing these additional settings is not an available option on Windows machines.
Option 3: save settings and just use rotate on each run
This is similar to option 2, but without executing the initialize_VPN
function on each run.
This is relevant for all Windows machines or Linux machines who do not wish to execute additional settings.
#do this once
initialize_VPN(save=1)
#open project on a later date and just use the following two lines of code:
rotate_VPN()
#do stuff
terminate_VPN()
Option 4: manual option
Create or obtain your own settings_nordvpn.txt file, place it in your project folder and use the rotate function#
For example, share particular settings with colleagues/friends who work on the same project by sending them your .txt settings file. Place it in your project folder and just use the rotate_VPN
function.
rotate_VPN()
#do stuff
terminate_VPN()
> See the demo.py file for a summary
1. Rotate between all available NordVPN servers at random. This differs from any other connection method since NordVPN automatically picks the most 'appropriate' (as in fastest) server in a particular region. This means that connecting to, let's say, the Netherlands means you'll often end up with the same server time and time again. The 'complete rotation' functionality allows you to completely randomize server selection.
initialize_VPN(area_input=['complete rotation'])
rotate_VPN()
#do stuff
terminate_VPN()
2. Provide additional settings and save these for later use, if so desired (only on Linux)
3. Login to NordVPN if logged out (only on Linux)
4. Take a random sample from a larger region
5.Spellchecker
6. Provide a list of connection options, which will be automatically incorporated into the nordvpn_settings.txt file
range_servers = range(800,837)
server_list = ["nl"+str(number) for number in range_servers]
instructions = initialize_VPN(area_input = server_list)
rotate_VPN(instructions)
6. NordVPN app starts automatically (if closed) on Windows. Connection process can also be monitored by checking the NordVPN app
1.Being able to log in through the Python interface. Windows users need to make sure they're already logged into the NordVPN app. The Windows app remembers your log in by default though, so this shouldn't cause too much trouble. So even when the app is closed, NordVPN-switcher should work.
2.Executing additional settings (e.g. killswitch etc.)
In this case, the VPN switcher basically serves the same function as the often-used proxy lists while scraping the web (e.g. with BeauitfulSoup), but without the common disadvantages associated with the latter.
To automate a particular task that benefits from being performed by many ip-addresses
For security reasons
I'm pretty sure there are plenty of other viable applications out there. NordVPN-switcher is extremely easy to implement, no matter the particular problem/project at hand.
Have fun!
FAQs
Rotate between different NordVPN servers with ease. Works both on Linux and Windows without any required changes to your code!
We found that nordvpn-switcher demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.