Skip to content

A pure Python implementation of the WireGuard protocol.

License

Notifications You must be signed in to change notification settings

rafa-br34/py-wg

Repository files navigation

Python WireGuard

Tests PyPI Downloads

A pure python implementation of the WireGuard protocol.

Table of contents

Motivation

Existing Python libraries for WireGuard rely on the system daemon, which limits flexibility, requires root access, and causes global network changes. A user-mode implementation avoids these issues, making setup easier and safer for isolated use cases. It also enables custom packet injection (IPv4/IPv6) without raw sockets, making it useful for things like anonymous SYN scans (given proper spoofing), dynamic IP hopping for scraping, or building VPN-like tools without system-wide impact. And finally, because why not? It's a fun project to learn about the WireGuard protocol and networking in general.

Performance

One major drawback of this implementation is its speed. While rewriting it in a faster language like C++ with Python bindings could solve this, it would also add significant complexity. For now, the focus is on optimizing the existing Python code as much as possible.

Installation

You can install py-wg from PyPI using

pip install wireguard-protocol

Alternatively, you can install directly from the repository using

pip install git+https://github.com/rafa-br34/py-wg.git

Usage

For usage examples please refer to the examples directory. The examples demonstrate how to use the library to create WireGuard peers, encode packets, send packets, and manage inbound packets.

A documentation will be added in the future, but for now, the examples should provide enough information to get started.

Testing and troubleshooting

If you encounter any issues while using the library run the test suite to check if any tests are failing. The tests can be run by using python run_tests.py in the root directory of the project. If anything fails or doesn't work properly please feel free to open an issue on the repository with the details of the issue and the output of the tests.

References

The following references were used while building this project:

About

A pure Python implementation of the WireGuard protocol.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages