Know-How: How-To: Get Forwarded Ports in Windows

atreyu

New Member
If you, like me, make use of the default forwarded ports feature of this wonderful VPN service - depending on wich VPN client you use, you might find that you need to use the "Port Calculator" on the Perfect-Privacy website to get your forwarded ports. Needing to log in to the web site and going to find the port calculator can sometimes be a hasstle, so I have created my own port calculator tool.

Please note that this is a PowerShell Script, so you need to run it in PowerShell.

Code:
$address = Get-NetIPAddress -InterfaceAlias "Ethernet 2" -AddressFamily IPv4
if (!$address) { $address = Get-NetIpAddress -AddressFamily IPv4 | Where-Object {$_.IPAddress -like "10.1.*" } }
if ($address) {
    Write-Host "Caltulating for IP Address" $address.IPAddress
    $octets = ($address.IPAddress).Split('.')
    For ($i=1; $i -lt 4; $i++)  {
        Write-Host "Port $i" -NoNewLine
        Write-Host ": " -NoNewLine
        Write-Host ($i*10000+($octets[2] % 16)*256+$octets[3])
        }
    }
else
    { Write-Host "Sorry!  I can't determine your VPN IP Address.  Are you sure it is connected?" }

How to use: Save the code to a file, something like "GetPorts.ps1", and then run it either using the standard notation, or via powershell.exe. If you have downloaded the attached text file, be sure to remove the superfluous .txt extension at the end.

Example From Powershel:
2019-01-15 10_00_37-VPNTest.png

Example from CMD:
2019-01-15 10_02_30-VPNTest.png

For interested parties: The formula for figuring out your ports is p*10000+(x mod 16)*256+y where p is the port 1, 2 and 3, and x is the third octet of your VPN IP Address and y is the fourth octect of your VPN IP Address.
 
Back
Top