Created
March 24, 2018 00:18
-
-
Save mrenouf/cf073fd70e081408bc7ee3661e6ce7b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Enable port forwarding when using Private Internet Access | |
# | |
# Usage: | |
# ./port_forwarding.sh | |
error( ) | |
{ | |
echo "$@" 1>&2 | |
exit 1 | |
} | |
error_and_usage( ) | |
{ | |
echo "$@" 1>&2 | |
usage_and_exit 1 | |
} | |
usage( ) | |
{ | |
echo "Usage: `dirname $0`/$PROGRAM" | |
} | |
usage_and_exit( ) | |
{ | |
usage | |
exit $1 | |
} | |
version( ) | |
{ | |
echo "$PROGRAM version $VERSION" | |
} | |
port_forward_assignment( ) | |
{ | |
echo 'Loading port forward assignment information...' | |
if [ "$(uname)" == "Linux" ]; then | |
client_id=`head -n 100 /dev/urandom | sha256sum | tr -d " -"` | |
fi | |
if [ "$(uname)" == "Darwin" ]; then | |
client_id=`head -n 100 /dev/urandom | shasum -a 256 | tr -d " -"` | |
fi | |
json=`curl "http://209.222.18.222:2000/?client_id=$client_id" 2>/dev/null` | |
if [ "$json" == "" ]; then | |
json='Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding' | |
fi | |
echo $json | |
} | |
EXITCODE=0 | |
PROGRAM=`basename $0` | |
VERSION=2.1 | |
while test $# -gt 0 | |
do | |
case $1 in | |
--usage | --help | -h ) | |
usage_and_exit 0 | |
;; | |
--version | -v ) | |
version | |
exit 0 | |
;; | |
*) | |
error_and_usage "Unrecognized option: $1" | |
;; | |
esac | |
shift | |
done | |
port_forward_assignment | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment