Port forwarding with a privateinternetaccess.com VPN

I use a VPN to encrypt all of my traffic. It's great when you're on a network that likes to monitor what you're doing, or when you want to be somewhat more difficult to trace, or when you need to get around location-based restrictions. But there's one problem: using a VPN means that there's an extra routing step between you and the internet, and if you want to have internet-facing ports open, they'll need to be forwarded.

The problem with that is that your host will usually have a number of clients sharing the same public IP address at the same time, so you can't just get them to forward whichever ports you want. The service I use does offer the ability to request that a port be forwarded, but you don't get to choose which port it is, you only get one, and it might change each time you connect. I want to have a port open for bittorrent, but I don't want to have to constantly check which port I got forwarded, then manually change the bittorrent settings. Frankly, that would just be way too much hassle. So I wrote a quick'n'dirty powershell script to do it for me, and now I'm archiving it here both so that I can find it later if need be, and because someone else might find it useful. The stuff highlighted in yellow is what you would need to change to your own personal values.


$ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter Index=TAP_INTERFACE_INDEX).IPAddress[0]
$web = New-Object System.Net.WebClient
$response = $web.UploadString
("https://www.privateinternetaccess.com/vpninfo/port_forward_assignment","user=USER&pass=PASS&client_id=CLIENT_ID&local_ip=$ip")
$port = $response.Substring(8,$response.IndexOf("}")-8)
$web.Credentials = new-object System.Net.NetworkCredential("UTORRENT_WEBGUI_USER","UTORRENT_WEBGUI_PASS")
$web.DownloadString("http://localhost:WEBUI_PORT/gui/?action=setsetting&s=bind_port&v=$port")

Since this is mostly for my own benefit, I won't add any more explanation. But if this happens to actually get read by somebody and you have questions about the script, feel free to ask them in the comments.

Comentários

Anônimo disse…
Hey there,
I'm trying to do the same thing except that I don't know anything about script writing :/
ive been searching google in hopes someone would have posted a sample, but you're the only that i've found! I know im going to sound like an idiot, but would being on osx change anything about the script? and or is there anything I should know if I wanted to try to use yours?
most appreciated :)
-aimee

Postagens mais visitadas deste blog

Le Jeu de Robin et Marion

Atomium, Flea Market, Fête de la BD... biking around Brussels

Pesquisando minhas origens