Giter Club home page Giter Club logo

pia-port-forwarding-script's Introduction

#PIA Port Forwarding Script

Copyright Kieran Gillibrand 2016 (MIT License)

Small Python script which enables port forwarding for a PIA VPN and prints the forwarded port.

Now finished but not perfect, personal project, etc.

#Usage

  • -h, --help: Show help.
  • -debug, --debug: Show debugging print statements.

#Dependancies

  • A Python 3 runtime
  • The Python 3 netifaces library (look for a package for your distribution or use Python's easy_install).
  • Netifaces is licensed under the MIT license: https://pypi.python.org/pypi/netifaces

#Script Operation

  • Check if the VPN is connected (the interface is active).
  • Generate a random client id
  • Send a get request to the PIA API endpoint with the client id in order to forward a port.
  • Parse the response and print it (port number or error message).

#Notes and Issues

  • This is my first Python program, made in my spare time but updated since.
  • This script will not work for other VPN providers.
  • Not all PIA gateways support port forwarding, make sure yours does: https://www.privateinternetaccess.com/pages/client-support/#sixth
  • This script is written to be portable but it needs the correct interface name which is an issue. Non GNU/Linux OS users might have a different interface name though Windows, Mac, and Debian based distros users can use the official PIA application which offers port forwarding built-in. The default interface is tun0 so update the INTERFACE variable if you are told that tun0 is not connected.
  • I've just switched to PIA's new API which allowed me to elimate the config file. The API tends to reset connections or not send responses when errors occur (if you try to port forward a 2nd time or port forward with an unsupported gateway for example). Because of that the error handling isn't brilliant right now.

#Downloading and Usage

  1. Download piascript.pyc from the releases page or download a source code archive (includes the script source along with the License and Readme files).

  2. Make the script/binary executable

  3. Connect to your PIA VPN

  4. Execute the script

  5. Add an exception in your firewall for the port and update the port settings for applications that you are using

#Constants (that you may want to change) Global

  • DEBUG: Flag that enables debugging print statements, set by the -debug/--debug option so you shouldn't need to edit it. Default: False

Main Method

  • RANDOM_BYTES_LENGTH: The number of bytes to read from os.urandom when generating the client id. The example script uses 100 lines of /dev/urandom instead which seemed excessive to me. Default: 3000
  • ENDPOINT: The API endpoint URL. Default: http://209.222.18.222:2000/
  • INTERFACE: The network interface that the VPN uses. Default: tun0
  • TIMEOUT: The timeout in seconds when calling the API. Default: 10

call_port_api()

  • DEFAULT_ENCODING: The backup encoding to decode the response with if the API doesn't return a content type header. Default: utf-8

#License MIT License

Copyright (c) 2016 Kieran Gillibrand

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pia-port-forwarding-script's People

Contributors

kgillibrand avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pia-port-forwarding-script's Issues

New PIA port forwarding API

Hey, nice script! I'm just opening this issue to let you know that we (PIA) have a new port forwarding API available. It'd be worth taking a look on our forums over here: https://www.privateinternetaccess.com/forum/discussion/23431/

Specifically, a few things you'll want to keep in mind with the new API are:

  • You only need to call the API once and the port will stay open forever.
  • There's no need to include the username/password or the local IP, which should help simplify configuration.
  • If port forwarding's already opened, the API will return nothing or reset the API connection (take a look at how the linked script in the topic above does it, to see how we handle this case).

If you run into any issues with it, feel free to reply here and I'll take a look.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.