Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_wireguard-0.1.4.tar.gz (69.9 kB view hashes)

Uploaded Source

Built Distribution

python_wireguard-0.1.4-py3-none-any.whl (68.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page