Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automate PrivateInternetAccess port forwarding with Deluge and Powershell
# Uses the PIA port forwarding API to request a port, then configures that port in Deluge
$deluge = "C:\Program Files (x86)\Deluge\deluge-console.exe"
$delugeconfig = "C:\Deluge"
$log = "C:\Deluge\output.txt"
# ---
Start-Transcript -Path $log
$ErrorActionPreference = "Stop"
Sleep -s 5
$clientid = New-Guid
$uri = "http://209.222.18.222:2000/?client_id=$clientid"
Write-Output URI: $uri
$out = Invoke-RestMethod -Uri $uri
$port = $out.port
Write-Output Port assigned: $port
IEX "& `"$deluge`" -c `"$delugeconfig`" `"config -s random_port false`""
IEX "& `"$deluge`" -c `"$delugeconfig`" `"config -s listen_ports ($port, $port)`""
Stop-Transcript
@gjosang

This comment has been minimized.

Copy link

commented Mar 19, 2018

I cant get this to work.. Seems like the issue is: $out = Invoke-RestMethod -Uri $uri
Any help would be much appreciate.

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a receive.
At line:1 char:8

  • $out = Invoke-RestMethod -Uri $uri
  •    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.