Skip to content

Instantly share code, notes, and snippets.

@2-click
Last active November 11, 2024 21:08
Show Gist options
  • Save 2-click/d3267354648bd6175db78ef171472e1d to your computer and use it in GitHub Desktop.
Save 2-click/d3267354648bd6175db78ef171472e1d to your computer and use it in GitHub Desktop.
Getting NordVPN Wireguard Keys from API with powershell
  1. Go to https://my.nordaccount.com/dashboard/nordvpn/manual-configuration/ and create an access token
  2. Copy token
  3. Use powershell to get Wireguard key
$username = "token"
$password = "<token goes here>"
$pair = "$($username):$($Password)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$encodedCredentials = [Convert]::ToBase64String($bytes)
$url = "https://api.nordvpn.com/v1/users/services/credentials"

$headers = @{
    Authorization = "Basic $encodedCredentials"
}

Invoke-RestMethod -Uri $url -Headers $headers -Method Get

id                   : xxxx
created_at           : xxxx
updated_at           : xxxx
username             : xxxxx
password             : xxxxx
nordlynx_private_key : xxxx
  1. Use powershell to get recommended server:
$server = Invoke-RestMethod -Uri "https://api.nordvpn.com/v1/servers/recommendations?&filters[servers_technologies][identifier]=wireguard_udp&limit=1"

$server | ForEach-Object {
    $wireguardTech = $_.technologies | Where-Object { $_.identifier -eq 'wireguard_udp' }
    if ($wireguardTech) {
        # Extract metadata values
        $publicKey = $wireguardTech.metadata | Where-Object { $_.name -eq 'public_key' } | Select-Object -ExpandProperty value
        
        # Output with additional metadata columns
        [pscustomobject]@{
            Name           = $_.name
            Load           = $_.load
            Station        = $_.Station
            TechnologyID   = $wireguardTech.id
            TechnologyName = $wireguardTech.name
            Identifier     = $wireguardTech.identifier
            CreatedAt      = $wireguardTech.created_at
            UpdatedAt      = $wireguardTech.updated_at
            PublicKey      = $publicKey
        }
    }
}

Name           : Germany xxx
Load           : 13
Station        : xx.xxx.xx.xxx
TechnologyID   : 35
TechnologyName : Wireguard
Identifier     : wireguard_udp
CreatedAt      : 2019-02-14 14:08:43
UpdatedAt      : 2019-02-14 14:08:43
PublicKey      : xxxxxx
@ehinkle27
Copy link

Great info the powershell stuff worked for me thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment