Git Product home page Git Product logo

pia-wg's Introduction

pia-wg

A WireGuard configuration utility for Private Internet Access

This is a Python utility that generates WireGuard configuration files for the Private Internet Access VPN service. This allows you to take advantage of the WireGuard protocol without relying on PIA's proprietary client.

This was created by reverse engineering the manual-connections script released by PIA. At this stage, the tool is a quick and dirty attempt to get things working. It could break at any moment if PIA makes changes to their API.

pia-wg runs on both Windows and Linux.

Windows

  • Install the latest version of Python 3
    • Select "Add Python to environment variables"
  • Install WireGuard

Open a command prompt and navigate to the directory where you placed the pia-wg utility. The following commands will create a virtual Python environment, install the dependencies, and run the tool.

python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
python generate-config.py

Follow the prompts. When finished, you can exit the virtual environment with the deactivate command.

The script should generate a .conf file that can be imported into the WireGuard utility.

Linux (Debian/Ubuntu)

Install dependencies, clone pia-wg project, and create a virual Python environment:

sudo apt install git python3-venv wireguard openresolv
git clone https://github.com/hsand/pia-wg.git
cd pia-wg
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Run the tool, and follow the prompts

python3 generate-config.py

Copy the .conf file to /etc/wireguard/, and start the interface

sudo cp PIA-Iceland-1605054556.conf /etc/wireguard/wg0.conf
sudo wg-quick up wg0

You can shut down the interface with sudo wg-quick down wg0

Check everything is working

Visit https://dnsleaktest.com/ to see your new IP and check for DNS leaks.

pia-wg's People

Contributors

hsand avatar jsaterdalen avatar konytech avatar michaelmagan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pia-wg's Issues

no connection

not having been able to connect recently with the vpn, I also tried to recreate my wg0.conf file but nothing I receive anything from the vpn

Configs only valid for a couple of hours

Hi, this isn't related to this project but I couldn't think of any other group that would be able to help me out.
So I've generated some configs, tested them, all is great.
After a couple of hours I can't reconnect to the servers with the config.
Is this something that is expected? If so I can't really use it on a router or with non PIA clients.

PIA may have updated API???

The PIA file generation still works but the file generated seems to have stopped working as of 1/3/22 after working for about 4 months without issue. The description does mention that PIA could change their API at any moment and break things. Well, I think it happened. Thanks anyway for the solution up until today :). OpenVPN still works with PIA but hopefully we can get WG back going.

No module named 'requests'

(venv) C:\Users\Downloads\pia-wg-master\pia-wg-master>python3 generate-config.py
Traceback (most recent call last):
File "C:\Users\Downloads\pia-wg-master\pia-wg-master\generate-config.py", line 1, in
from piawg import piawg
File "C:\Users\Downloads\pia-wg-master\pia-wg-master\piawg.py", line 1, in
import requests
ModuleNotFoundError: No module named 'requests'

Script to rename config files and generate QR configs

/Hi, I couldn't use the configfiles that this script produces as the filenames are longer then the 16 characters that wireguard supports out off the bag.
So I wrote/hacked-up this script that will rename the configs. Someone might find it useful.

#!/bin/bash
# pia-wg config file as parameter

file=$1
ip=`grep Endpoint $file | cut -d"=" -f2 | cut -d ":" -f1 | xargs `
#echo "ip:"$ip
hex=`gethostip -x $ip | tr '[:upper:]' '[:lower:]'`
#echo "hex:"$hex
mv $file "pia_"$hex".conf"
qrencode -t "png" -o "pia_"$hex".png" -r "pia_"$hex".conf"


ERROR: Conflicting Dependencies

Please excuse my lack of python knowledge. Your how-to is very user friendly, however I have a dependency error that I do not know how to resolve. Here is the text from the command line:

**ERROR: Cannot install -r requirements.txt (line 5) and urllib3==1.26.6 because these package versions have conflicting dependencies.

The conflict is caused by:
The user requested urllib3==1.26.6
requests 2.24.0 depends on urllib3!=1.25.0, !=1.25.1, <1.26 and >=1.21.1

To fix this you could try to:

  1. loosen the range of package versions you've specified
  2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies**

Thank you for your assistance.

wg0 already exists and no internet after install

I'm trying to set this up on Raspbian "buster." I followed the instructions, but when I run the last command:

sudo wg-quick up wg0

I get the following message:

wg-quick: 'wg0' already exists

And also now the device no longer has internet access while still being accessible over LAN.

Dedicated Ip feature

Thanks for this useful piece of codes ! I use it regularly on my router to get PIA Wireguard working properly.

Is there any plan to implement the dedicated IP feature in your code ? I know it should be possible by providing somehow the unique token generated by PIA.

Upload to PyPI?

Hi! Thank you for the script, @hsand! Any chance you're interested in uploading it to pypi.org?

This would really simplify installation, especially for those who use pipx or don't mind installing it without venv.

Not Able to Connect

I used the tool to generate the config and it said everything worked but when I put this in my wireguard set up it doesn't work...

[Interface]
Address = 10.38.134.8
PrivateKey = <>
DNS = 10.0.0.243,10.0.0.242

[Peer]
PublicKey = <>
Endpoint = 46.246.3.218:1337
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Not being able to enter password

When i come to the part of entering usn&pwd(all previous steps were successfully operated), I could enter the username but I'm not able to enter the password.

Error happens :/

(venv) PS C:\pia-wg-master> python generate-config.py
Traceback (most recent call last):
File "C:\pia-wg-master\generate-config.py", line 6, in
pia = piawg()
^^^^^^^
File "C:\pia-wg-master\piawg.py", line 16, in init
self.get_server_list()
File "C:\pia-wg-master\piawg.py", line 26, in get_server_list
data = json.loads(r.text.splitlines()[0])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\foxi\AppData\Local\Programs\Python\Python312\Lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\foxi\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\foxi\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Loggin error

I encountered a problem when asked for my PIA credentials, it says "Error logging in, please try again ..."
I'm sure my credentials are working.
I tested several servers and all indicated this error to me.

Generate-config.py fails with FileNotFoundError

I grabbed pia-wg today and installed python 3.10.2 and follow ed the readme.

Generate-config.py fails with "FileNotFoundError: [WinError 2] The system cannot find the file specified" and i have no idea why.

Here's my whole console output:

(venv2) D:\pia-wg-master\pia-wg-master>generate-config.py
Traceback (most recent call last):
File "D:\pia-wg-master\pia-wg-master\generate-config.py", line 9, in
pia.generate_keys()
File "D:\pia-wg-master\pia-wg-master\piawg.py", line 54, in generate_keys
self.privatekey = subprocess.run(['wg', 'genkey'], stdout=subprocess.PIPE, encoding="utf-8").stdout.strip()
File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

Port forward option?

Hello, Thanks for this super helpful script! This may be a dead project but I'll ask anyway.

Would it be possible to add a port forwarding option?

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.