WireGuard-Schlüssel (privat & öffentlich) in Python ohne Abhängigkeiten generieren
English
Deutsch
Der folgende Code ermöglicht das Generieren eines WireGuard-privaten und -öffentlichen Schlüssels, ohne eine Python-Bibliothek installieren zu müssen.
generate_wireguard_keys.py
import subprocess
def generate_wireguard_keys():
"""
Generate a WireGuard private & public key
Requires that the 'wg' command is available on PATH
Returns (private_key, public_key), both strings
"""
privkey = subprocess.check_output("wg genkey", shell=True).decode("utf-8").strip()
pubkey = subprocess.check_output(f"echo '{privkey}' | wg pubkey", shell=True).decode("utf-8").strip()
return (privkey, pubkey)Verwendungsbeispiel:
generate_wireguard_example.py
print(generate_wireguard_keys())Ausgabe:
generate_wireguard_output.txt
('KIm+ZlY86I+cInG4FWZpKmhADUnxrqhdtQ5UzaFbuVs=', 'ctX9oUw+CkRe7GfSmUHAB9JjLfQWALOs0gXU9Ikhg1g=')Check out similar posts by category:
Networking, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow