Last active
April 16, 2019 19:47
-
-
Save boop5/a24d0510bb1a0ad760e7bf9c624df37a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$options = @{ | |
location = "E:\Cloud\Documents\OpenVPN\config\" | |
country = "Germany" | |
}; | |
# ================================================= | |
Clear-Host | |
$url = 'https://nordvpn.com/api/server' | |
# GET NEW HOSTS | |
Write-Host "Download Active Servers from $url" | |
$hosts = $(Invoke-WebRequest $url | | |
ConvertFrom-Json) | | |
Where-Object { $_.country -eq $options.country ` | |
-and ` | |
$_.features.openvpn_udp -eq "True" } | | |
Sort-Object { $_.load } | | |
Select-Object -First 15 | |
Write-Host "Found $($hosts.length) new hosts" | |
if($hosts.length -gt 0) | |
{ | |
# CLEAR CURRENT CONFIG | |
Write-Host "Clear current configurations" | |
Get-ChildItem $options.location | | |
Where-Object { $_.name -match '[0-9]{1,3}\%\-[a-z]{2,3}[0-9]{1,3}\.ovpn'} | | |
ForEach-Object { | |
Write-Host "Delete $_" | |
$_ | Remove-Item | |
} | |
# DOWNLOAD CONFIGURATION | |
$hosts | ForEach-Object { | |
$server = $_ | |
Write-Host "Download Configuration for $($server.domain)" | |
$url = "https://downloads.nordcdn.com/configs/files/ovpn_udp/servers/$($server.domain).udp.ovpn" | |
$name = "$('{0:00}' -f $server.load)%-$($server.domain.Split('.')[0])" | |
$fileName = Join-Path $options.location "$name.ovpn" | |
$cfg = $(Invoke-WebRequest $url) -replace 'auth-user-pass','auth-user-pass credentials' | |
$cfg | Out-File $fileName -Encoding UTF8 | |
} | |
} | |
Write-Host "`nScript finished.`nPress any key to continue..."; | |
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment