PowerShell Port Forwarding For Utorrent/Qbittorrent/Other for new API
This is a new script for Port forwarding automation. Currently it works for Utorrnet and Qbitorrent through powershell. It requires Powershell 3.0 and above and windows 7 and above to work.
The script is now in the second post of this thread.
What this script does
When running this script it will connect to a pia server that you choose. If available it will request a port forward and update your app to listen on that port. It can also monitor the vpn and if it sees it disconnected it will reconnect and ask for a port forward again.
Known Problems
1. If using auto-check, Please turn off user account control or run as administrator. It needs the privilege to start and stop the openvpn service.
2. Spaces in windows user names will cause the power shell script not to run if you have the script located on the desktop/documents/etc. Read this for more info or work around. This is not a problem with my script but a limitation of powershell.
The old script this is based on is here
Problems
Get it working first without Advance routing First
ENABLEAUTOCHECK
To enable this set $ENABLEAUTOCHECK = $true
If you set openvpn to run as a service, and this is $true, it will check
every minute to make sure you are connected, if not it will try to
reconnect you every two minutes.
Go to this website for more info on openvpn service http://vpnblog.info/openvpn-startup-windows.html.
Basically do this.
The Windows installer will set up a Service Wrapper, but leave it turned off by default. We need enable OpenVPN service and make sure it's set to Startup Type to manual. The script will start it and monitor it.
1) Open Control Panel -> Administrative Tools
2) Find and open Services
3) Find OpenVPN Service, right mouse click and Properties4) Set Startup type to Manual
5) When you started computer, the OpenVPN Service Wrapper will scan the \Program Files\OpenVPN\config ( for 64 bit OS \Program Files(x86)\OpenVPN\config ) folder for .ovpn configuration files and starting a separate OpenVPN process on each file( So only have one in there).
Once OpenVPN started as a service on Windows, the only way to control it is in Services, right mouse click on OpenVPN service and it gives start/stop control.
Advance Routing
To enable this set $EnabledAdvanceRouting = $true
What is Advance Routing, this is when you set your nic to a static ip address, and
don't assign a dns or gateway to the nic. Basically your computer
doesn't know how to get to the internet. What this does it adds a
temporary route to a dns server and looks up pia server address. It
then remove the route to the dns server and adds a route to pia so your
computer knows how to connect to the pia server. In then updates
openvpn connection file and adds the ip address and then openvpn is able
to connect.
Why this? if your computer doesn't know how to
connect to the internet, apps can't leak your real ip address, ex
Utorrent. so you can't get on the internet until openvpn connects,and
if the connection drops, your back to no internet.
Here the steps to get this to work.
1. install openvpn, (update the path $pathtoovpn if you installed the 64bit version)
2. copy one pia openvpn config to the config directory, rename it to pia
3. make an authpass.txt, first line your username, second line your password
4. edit pia.ovpn file add these three lines
auth-user-pass authpass.txt
route-metric 512
route 0.0.0.0 0.0.0.0
Your config directory needs at least these files
for standard encryption you need
For strong encryption you need these files also
Get the files from here https://www.privateinternetaccess.com/openvpn/openvpn-strong-tcp.zip
for Legacy encryption you need these files also
Get the files from here https://www.privateinternetaccess.com/openvpn/openvpn-ip-tcp.zip
The pass.txt looks like this
The script is now in the second post of this thread.
What this script does
When running this script it will connect to a pia server that you choose. If available it will request a port forward and update your app to listen on that port. It can also monitor the vpn and if it sees it disconnected it will reconnect and ask for a port forward again.
Known Problems
1. If using auto-check, Please turn off user account control or run as administrator. It needs the privilege to start and stop the openvpn service.
2. Spaces in windows user names will cause the power shell script not to run if you have the script located on the desktop/documents/etc. Read this for more info or work around. This is not a problem with my script but a limitation of powershell.
The old script this is based on is here
Problems
Get it working first without Advance routing First
ENABLEAUTOCHECK
To enable this set $ENABLEAUTOCHECK = $true
If you set openvpn to run as a service, and this is $true, it will check
every minute to make sure you are connected, if not it will try to
reconnect you every two minutes.
Go to this website for more info on openvpn service http://vpnblog.info/openvpn-startup-windows.html.
Basically do this.
The Windows installer will set up a Service Wrapper, but leave it turned off by default. We need enable OpenVPN service and make sure it's set to Startup Type to manual. The script will start it and monitor it.
1) Open Control Panel -> Administrative Tools
2) Find and open Services
3) Find OpenVPN Service, right mouse click and Properties4) Set Startup type to Manual
5) When you started computer, the OpenVPN Service Wrapper will scan the \Program Files\OpenVPN\config ( for 64 bit OS \Program Files(x86)\OpenVPN\config ) folder for .ovpn configuration files and starting a separate OpenVPN process on each file( So only have one in there).
Once OpenVPN started as a service on Windows, the only way to control it is in Services, right mouse click on OpenVPN service and it gives start/stop control.
Advance Routing
To enable this set $EnabledAdvanceRouting = $true
What is Advance Routing, this is when you set your nic to a static ip address, and
don't assign a dns or gateway to the nic. Basically your computer
doesn't know how to get to the internet. What this does it adds a
temporary route to a dns server and looks up pia server address. It
then remove the route to the dns server and adds a route to pia so your
computer knows how to connect to the pia server. In then updates
openvpn connection file and adds the ip address and then openvpn is able
to connect.
Why this? if your computer doesn't know how to
connect to the internet, apps can't leak your real ip address, ex
Utorrent. so you can't get on the internet until openvpn connects,and
if the connection drops, your back to no internet.
Here the steps to get this to work.
1. install openvpn, (update the path $pathtoovpn if you installed the 64bit version)
2. copy one pia openvpn config to the config directory, rename it to pia
3. make an authpass.txt, first line your username, second line your password
4. edit pia.ovpn file add these three lines
auth-user-pass authpass.txt
route-metric 512
route 0.0.0.0 0.0.0.0
Your config directory needs at least these files
pass.txt
pia.ovpn
for standard encryption you need
ca.rsa.2048.crtGet the Files from here https://www.privateinternetaccess.com/openvpn/openvpn-tcp.zip
crl.rsa.2048.pem
For strong encryption you need these files also
ca.rsa.4096.crt
crl.rsa.4096.pem
Get the files from here https://www.privateinternetaccess.com/openvpn/openvpn-strong-tcp.zip
for Legacy encryption you need these files also
ca.crt
crl.pem
Get the files from here https://www.privateinternetaccess.com/openvpn/openvpn-ip-tcp.zip
The pass.txt looks like this
piausernameThe pia.opvn file looks like this
piapassword
client
dev tun
proto udp
remote 172.98.67.44 1198
resolv-retry infinite
nobind
persist-key
persist-tun
cipher aes-128-cbc
auth sha256
tls-client
remote-cert-tls server
auth-user-pass pass.txt
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.rsa.2048.pem
ca ca.rsa.2048.crt
disable-occ
route-metric 512
route 0.0.0.0 0.0.0.0
Comments
3.01 Fix to work on Windows 10, still works on 7+
3.02 Clean up old code left over, that was not used
3.03 Added options for Legacy,Standard, and Strong encryption
3.10 Better detection when vpn connects, watch if the ip address changes, if so request new port, added option for qbittorrent to look for stalled qbittorrent. Added fix for refer header for qbittorrent 3.3.14. Cleaned up code on application connections.
3.11 Fix screen issue, clear out old variables not used anymore.
3.12 It will request port even if no application is running.
3.13 It will update the port of the program if it couldn't before for some reason, example not running.
3.14 Better support for Windows 10, script will prompt to run as admin if advance features enabled.
3.15 Correct Spelling, list version in title bar, added comment to this web address.