A python wrapper for controlling Wireguard
Project description
Python Wireguard interface
Library for controlling Wireguard using python.
Installation
To install this package, use pip:
pip install python_wireguard
Security remark
Changing network interface settings, and interacting with Wireguard, is only possible as the root user by default.
Usage
This package was designed with a client/server infrastructure in mind. This differs from the 'default' usage of Wireguard, which is peer to peer. Because of this, there is a different set of functions required depending on whether you are writing client-side code or server-side code. We will now discuss an example workflow for setting up a client-server connection to Wireguard.
Generate key pair
Both the client and the server need a key pair.
import python_wireguard as wg
private, public = wg.key_pair()
By default the key is an array of bytes. In order to make it more usable, you can convert it to a base64 string:
string = wg.key_to_base64(public)
print(string)
Creating a key from a base64 string is also possible, which is useful for creating one for the other device's public key:
srv_public = wg.key_from_base64("some string containing a base64 key")
Server
wg.create_server("wg-srv", 12345, private, "10.0.0.1/24")
wg.enable_device("wg-srv")
wg.server_add_peer("wg-srv", client_public, "10.0.0.2")
Client
wg.setup_client_connection("wg-client", private, "10.0.0.2/24", srv_public, "public ip of VPN server", 12345)
wg.enable_device("wg-client")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_wireguard-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c0ef987a105124bf4d20ccd21a8f88c9625b59c7096a88744416daf9f6b18bf |
|
MD5 | 6d0dbf899be4524e4d085eae6f220783 |
|
BLAKE2b-256 | 399799c8f9e5f3186093cb05790d7e77588fd4a585295d0485dc7d21290090a5 |