Skip to content

Instantly share code, notes, and snippets.

@nphyx
Last active December 23, 2019 03:23
Show Gist options
  • Save nphyx/e24c5349469f8dbca627761fafd57fbe to your computer and use it in GitHub Desktop.
Save nphyx/e24c5349469f8dbca627761fafd57fbe to your computer and use it in GitHub Desktop.
Script to get a peer port for Private Internet Access
#! /bin/bash
#
# Enable port forwarding
#
# Based on another script found somewhere else, but this one gets user/pass automatically and requires sudo.
#
# Usage:
# $ sudo piaport
port_forward_assignment( )
{
if [ "$(uname)" == "Linux" ]; then
local_ip=`ip addr show tun0|grep -oE "inet *10\.[0-9]+\.[0-9]+\.[0-9]+"|tr -d "a-z :"|tee /tmp/vpn_ip`
client_id=`head -n 100 /dev/urandom | md5sum | tr -d " -"`
fi
if [ "$(uname)" == "Darwin" ]; then
local_ip=`ip addr show tun0 | grep "inet " | cut -d\ -f2|tee /tmp/vpn_ip`
client_id=`head -n 100 /dev/urandom | md5 -r | tr -d " -"`
fi
json=`wget -q --post-data="user=$USER&pass=$PASSWORD&client_id=$client_id&local_ip=$local_ip" -O - 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment' | head -1`
port=`echo $json | grep -o "[0-9]*"`
echo $port
}
EXITCODE=0
PROGRAM=`basename $0`
VERSION=1.0
USER=`awk "NR==1{print;exit}" /etc/private-internet-access/login.conf`
PASSWORD=`awk "NR==2{print;exit}" /etc/private-internet-access/login.conf`
port_forward_assignment
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment