/nordVPNServers

Lists of all Nord VPN servers in various formats (csv, javascript, json, php)

Primary LanguagePHP

Current Active NordVPN Servers

Current Active NordVPN Servers (getActiveServers.php)

Background

I've worked in AdTech for >20 years during which time we've had to build tools that help us manage and debug ad-delivery on our site. One specifc issue we have faced is managing ads delivered to different Geo-Locations.

We make use of NordVPN to help us appear as if we are in different countries, which is fine for manual checking BUT what we really wanted to do is be able to leverage Nord in out automated testing tools.

The issue we found was, eve though we had a list of >6000 named servers from Nord these are not always guaranteed to be currently active. So a server may work one day but not the next.

We wanted to find a way to access ONLY active servers and this tool is the result of that.

Every 15mins (via crontab) this tool checks the current active servers from the Nord website (URL) and provides this in easily consumable files that can be loaded into your app as json, js, txt or csv values.

serverlist.txt - returns a formatted list of servers, one domain per line
serverlist.json - a json array of servers
serverlist.js - returns an array called 'nordServers'
serverlist.csv - csv delimited list of servers
serverlist.log - plain ntext file with Date/Time when these file last updated

About the code

The core of this tool (getActiveServers.php) is a script I run via the crontab.

It sits in a folder outside of the webserver directory and is executed via the crontab every 30mins (configurable).

It's quite a yeavy script and makes upwards of 200 requests to the Nord servers so ensuring it's not publically executable is important.

It can take up to 2mins to run, so you may need to extend the timeout in your php config, NB: I'm hoping to refactor the code to use cURL multi-threading in the future.

Once all results are collected it then outputs a list of active servers it's obtained into a number of different file formats: txt, json, js and csv

It then copies these files to another directory (the files you can access above) to publically expose them for your use.

If you do not want to copy these files just comment out the line starting '$conf["destinationDir"]'

Configuration

To get this working on your setup you'll need to configure a handful of parameters. These are all at the start of the script and are prefixed $conf[VAR_NAME]

     //////////////////////////////////////////////////////////////////////////////////////////
     // CONFIGURATION
     //////////////////////////////////////////////////////////////////////////////////////////
       $conf["installDir"]     = __DIR__ . "/";  // the dir this script is installed in eg; /home/nordVPN/
       $conf["destinationDir"] = "DIR_TO_COPY_FILES_TO";               // the dir into which you want to copy the serverlist files eg; /home/www/nord/
       $conf["filename"]       = "serverlist";                         // name of the files output , these are appended by file extensions in the next line
       $conf["output_types"]   = ['txt','json','js','csv','log'];      // list of support file outut types
       $conf["serverMaxCount"] = 300;                                  // each country is represented as a number, 200 should mean we capture all known countries - this needs optimising!
     //////////////////////////////////////////////////////////////////////////////////////////

NB: If you do not want to copy files to a production web folder then simply comment the line out.

Crontab:
Change the location according to where you've installed this script. The following will execute every 15mins

    */15 * * * * php /DIR_IN_WHICH_THIS_SCRIPT_WILL_RUN/getActiveServers.php

Permissions:
This should all work as is... however, you may need to ensure you have permissions to write and copy fils to the respective directories.