PowerShell PIA VPN Port Forwarding Assignment Reservation Script

This script will loop continuously and keep your port forwarding assignment updated and assigned to your IP while you are connected to the Private Internet Access VPN (PIA VPN).

Configure the $user, $pass, and $clientID variables per your PIA account information. The result from the webrequest which contains the assigned port will be written to the PowerShell console. You must be connected to the PIA VPN before running this script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# PowerShell Private Internet Access (PIA) VPN Port Forwarding Assignment Reservation Script
# POST to:  https://www.privateinternetaccess.com/vpninfo/port_forward_assignment
# Vars:     user=username
#           pass=password
#           client_id=a random string that no one should be able to guess, use the same string every time
#           local_ip=the 10.x.x.x IP you get assigned after connecting to the VPN

$user = 'user'
$pass = 'pwd'
$clientID = '2vn03242435fvdfasc349c234'

$i="go"
Do {
    cls
    $timestamp = (Get-Date –f o)
    $ip2=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1 -and $_.Description -like "*TAP-Windows Adapter V9*" }
    $ip = $ip2.ipaddress[0]
    $postParams = @{user=$user;pass=$pass;client_id=$clientID;local_ip=$ip}
    $info = Invoke-WebRequest -Uri https://www.privateinternetaccess.com/vpninfo/port_forward_assignment -Method POST -Body $postParams
    Write-Host $info.Content
    Write-Host "$timestamp | sleeping..."
    sleep -Seconds 3200
    $i = "go"
}while ($i = "go")

Leave a Reply

Your email address will not be published. Required fields are marked *