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.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eeed83bf2f4c4e8b43e432748c178494ba712ef98bf5c18b44324f8e0c8a239 |
|
MD5 | b0971398e6690760282de3ea65b74c26 |
|
BLAKE2b-256 | 6cbe7522edefc7fe4b7214adcec861065d96f43b3a235b4482be7673280c0160 |