Skip to content

Commit

Permalink
Add instructions to README
Browse files Browse the repository at this point in the history
Signed-off-by: Evandro Camargo <evandro@camargo.uk>
  • Loading branch information
nmindz committed May 5, 2024
1 parent 81be09d commit 068f186
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 68 deletions.
21 changes: 12 additions & 9 deletions NordVpnToWireguard.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Show-Help {
Write-Host "OPTION includes:"
Write-Host " -Version - prints out version information."
Write-Host " -Country <country> - Country to connect to (ex. Canada). If option is not provided, NordVPN will get a wireguard configuration for the recommended country, unless a valid city name is provided."
Write-Host " -ID <id> - ID to connect to (ex. 1234)."
Write-Host " -Id <id> - ID to connect to (ex. 1234)."
Write-Host " -Help - displays this message."
exit
}
Expand All @@ -35,8 +35,11 @@ if ($Country) {
# Write-Host "DEBUG: Found country $Country"
}
if ($Id) {
$Country = $Country -replace '_', ' '
# Write-Host "DEBUG: Found ID $Id"
if (-not $Country) {
Write-Host "While specifying -Id, you also need to specify -Country. Exiting..."
exit 1
}
}

# Check if the script is running as an administrator
Expand All @@ -46,8 +49,8 @@ if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
if ($Country) {
$params += " -Country `"$Country`""
}
if ($ID) {
$params += " -ID `"$ID`""
if ($Id) {
$params += " -Id `"$Id`""
}
if ($Version) {
$params += " -Version"
Expand Down Expand Up @@ -98,17 +101,17 @@ elseif ($Country -and -not $Id) {
exit 1
}
}
elseif ($Id -and -not $Country) {
Write-Host "Getting configuration for recommended server by ID $Id"
nordvpn -c -i $Id > $null 2>&1
elseif ($Id -and $Country) {
Write-Host "Getting configuration for recommended server in $Country with ID $Id"
nordvpn -c -n "$Country #$Id" > $null 2>&1

if ($LASTEXITCODE -ne 0) {
Write-Host "Unable to connect to NordVPN."
exit 1
}
}
elseif ($Id -and $Country) {
Write-Host "Please specify either Country group or ID, not both."
elseif (-not $Country -and $Id) {
Write-Host "Please provide the Country group for the provided ID."
}

# Pooling for nordlynx interface
Expand Down
168 changes: 109 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,115 +1,165 @@
# [Wireguard](https://www.wireguard.com) configuration file generator for a [NordVPN](https://nordvpn.com)
# NordVPN to Wireguard Configuration Generator

A `bash` scripts that generates [Wireguard](https://www.wireguard.com) configuration file for a [NordVPN](https://nordvpn.com) connection.
This tool is a bash script for generating a Wireguard configuration file for a NordVPN connection.

## INSTALL
## Table of Contents

This guide assumes the use of [Ubuntu](https://ubuntu.com). A similar install procedure will work on other distros.
- [Overview](#overview)
- [Installation](#installation)
- [Cloning the Project](#cloning-the-project)
- [Requirements and Dependencies](#requirements-and-dependencies)
- [NordVPN Account Login](#nordvpn-account-login)
- [Protocol Change to NordLynx](#protocol-change-to-nordlynx)
- [Generating the Wireguard Configuration Files](#generating-the-wireguard-configuration-files)
- [Importing the Wireguard Configuration Files](#importing-the-wireguard-configuration-files)

### Clone this project
> Note: This guide assumes the use of Ubuntu for Linux and Windows 11 for Windows. A similar install procedure will work on other distributions/versions.
First let's clone this project so that you'll have the script on your target [Ubuntu](https://ubuntu.com) system.
## Overview

### Install required packages
This guide provides instructions on how to generate a Wireguard configuration file for a NordVPN connection.

## Installation

### Cloning the Project

Clone this project to have the script on your target Ubuntu system.

### Requirements and Dependencies

#### Linux

* curl
* jq
* net-tools
* nordvpn

You may install the required packages by running the following command:

```bash
sudo apt install wireguard curl jq net-tools
```

### Install [NordVPN](https://nordvpn.com) client

Execute the following command and follow the on screen instructions:
And then, the NordVPN client, with the command below following the onscreen instructions:

```bash
sh <(curl -sSf https://downloads.nordcdn.com/apps/linux/install.sh)
```

## Login to your [NordVPN](https://nordvpn.com) account
#### Windows

The procedure differs if you have `MFA` enabled on your account:
* Powershell 7.x
* NordVPN Client

1. `MFA` is ENABLED on your account
You may install the latest version by downloading the package from [PowerShell/powershell](https://github.com/PowerShell/powershell/releases) releases, or if you prefer `winget`:

```pwsh
winget install --id Microsoft.Powershell --source winget
```
You can get more information about the above command from Microsoft's documentation [here](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows).

For the NordVPN client, simply follow the [official download page instructions](https://nordvpn.com/download/windows/).

## NordVPN Account Login

**If you're on Windows, please ensure `nordvpn` is in your `PATH` before proceeding, or adjust accordingly.**

The login procedure will differ based on whether you have MFA enabled:

1. MFA is **ENABLED**:

```bash
nordvpn login
```

This will return a URL link.
Open the link on any browser, on any machine and perform the login.
Cancel out of the `Open with` popup, and copy the link that is assigned to the `Continue` link, under the message saying `You've successfully logged in`.
This will return a URL link.
Open the link on any browser, on any machine and perform the login.
Cancel out of the `Open with` popup, and copy the link that is assigned to the `Continue` link, under the message saying `You've successfully logged in`.

Back to the terminal
Back to the terminal

```bash
nordvpn login --callback "<The link you copied>"
```
```bash
nordvpn login --callback "<The link you copied>"
```

And it will log you in.
And it will log you in.

2. `MFA` is NOT ENABLED on your account
2. MFA is **NOT ENABLED**:

Use `legacy` username and password to login.

> Note: This will NOT work if you have `Multi Factor Authentication` enabled. (See above for the `MFA` method)
```bash
nordvpn login --legacy​
```
```bash
nordvpn login --legacy​
```

If you have Multi Factor Authentication enabled, this will not work. Refer to the MFA method mentioned above.

## Change protocol to NordLynx
## Protocol Change to NordLynx

After a successful login, please set [NordVPN](https://nordvpn.com) to use `NordLynx` protocol.
Set NordVPN to use the NordLynx protocol after successful login by using the following command:

#### Linux
```bash
sudo nordvpn set technology nordlynx
```

## Generate [Wireguard](https://www.wireguard.com) configuration files
#### Windows (Elevated)
```pwsh
nordvpn set technology nordlynx
```

## Generating the [Wireguard](https://www.wireguard.com) Configuration Files

The script is quite simple and can be run without parameters to generate a config file for the recommended server:
For Linux, it is quite simple and can be run without parameters to generate a config file for the recommended server:

#### Linux
```bash
$ ./NordVpnToWireguard.sh
Getting configuration for recommended server...
Wireguard configuration file NordVPN-us1234.conf created successfully!
```

Requesting a specific country:
Generating the configuration on Windows requires the NordVPN Desktop app to be executed. The default behavior would be the same as "Quick Connect".
The Windows NordVPN desktop application does not offer a rich interface that lets you connect directly from CLI to a server like it does on Linux.

```bash
$ ./NordVpnToWireguard.sh --country Canada
Getting configuration for recommended server in Canada
Wireguard configuration file NordVPN-ca1234.conf created successfully!
```
It allows you to request for specific parameters, but connection itself has to be established through the GUI.

Requesting a specific city
```bash
$ ./NordVpnToWireguard.sh --city Berlin
Getting configuration for recommended server in Berlin
Wireguard configuration file NordVPN-de1234.conf created successfully!
#### Windows
```pwsh
PS > .\NordVpnToWireguard.ps1
Relaunching script with administrator rights... - -NoExit -File ".\NordVpnToWireguard.ps1"
Getting configuration for recommended server...
Checking for NordLynx interface... Attempt 1 of 12
Checking for NordLynx interface... Attempt 2 of 12
Checking for NordLynx interface... Attempt 3 of 12
Checking internet conectivity...
Attempt failed: Unable to confirm internet connectivity. Retrying in 5 seconds...
Attempt failed: Unable to confirm internet connectivity. Retrying in 5 seconds...
Attempt failed: Unable to confirm internet connectivity. Retrying in 5 seconds...
Attempt failed: Unable to confirm internet connectivity. Retrying in 5 seconds...
Attempt failed: Unable to confirm internet connectivity. Retrying in 5 seconds...
Internet connectivity confirmed.
Wireguard configuration file NordVPN-us9388.conf.nordvpn.com created successfully!
```
Note: If you notice that after the NordVPN desktop app loads, it doesn't automatically connect, you may manually attempt to establish the connection through the GUI.
Sometimes the application will stand by and not connect as expected on Windows. It is bit wonky.

Requesting a specific country and city

```bash
$ ./NordVpnToWireguard.sh --country Japan --city Tokyo
Getting configuration for recommended server in Japan, city: Tokyo
Wireguard configuration file NordVPN-jp1234.conf created successfully!
```
You may also explore some alternative options with parameters. Here are some examples:

Getting help:
#### Linux
- For a specific country: `./NordVpnToWireguard.sh --country Canada`
- For a specific city: `./NordVpnToWireguard.sh --city Berlin`
- For a specific country and city: `./NordVpnToWireguard.sh --country Japan --city Tokyo`
- For help: `./NordVpnToWireguard.sh --help`

```bash
$ ./NordVpnToWireguard.sh --help
Usage: NordVpnToWireguard [OPTIONS]
OPTION includes:
-v | --version - prints out version information.
-c | --country - Country to connect to (ex. Canada). If option is not provided, NordVPN will get a wireguard configuration for the recommended country, unless a valid city name is provided.
-s | --city - City to connect to (ex. Toronto). When country option is provided, NordVPN will look for the the city within the country and return the fastest server. If no country is provided, NordVPN will look up the fastest server for a city matching the name.
-h | --help - displays this message.
```
#### Windows
- For a specific country: `.\NordVpnToWireguard.ps1 -Country "United_States"`
- For a specific country and server: `.\NordVpnToWireguard.ps1 -Country "United_States" -Id "9388"`
- For help: `.\NordVpnToWireguard.ps1 -Help`

## Use the generated [Wireguard](https://www.wireguard.com) configuration files
## Importing the [Wireguard](https://www.wireguard.com) Configuration Files

Import the file/s with the [Wireguard](https://www.wireguard.com) client in any platform and activate the `VPN`.
With the [Wireguard](https://www.wireguard.com) client on any platform, import and activate the VPN with the generated files.

0 comments on commit 068f186

Please sign in to comment.