mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-06 22:32:54 +02:00
Add WireGuard (wg) Command Output Parser (#606)
* feat: add parser to parse the output of wg * fixup! feat: add parser to parse the output of wg * feat: Add tests for windows 10 --------- Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
This commit is contained in:
@ -225,6 +225,7 @@ parsers: List[str] = [
|
||||
'vmstat-s',
|
||||
'w',
|
||||
'wc',
|
||||
'wg-show',
|
||||
'who',
|
||||
'x509-cert',
|
||||
'x509-csr',
|
||||
|
270
jc/parsers/wg_show.py
Normal file
270
jc/parsers/wg_show.py
Normal file
@ -0,0 +1,270 @@
|
||||
r"""jc - JSON Convert `wg show` command output parser
|
||||
|
||||
Parses the output of the `wg show all dump` command, providing structured JSON output for easy integration and analysis.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ wg show all dump | jc --wg-show
|
||||
|
||||
or
|
||||
|
||||
$ jc wg-show
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc
|
||||
result = jc.parse('wg-show', wg_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"device": string,
|
||||
"privateKey": string,
|
||||
"publicKey": string,
|
||||
"listenPort": integer,
|
||||
"fwmark": integer,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": string,
|
||||
"presharedKey": string,
|
||||
"endpoint": string,
|
||||
"latestHandshake": integer,
|
||||
"transferRx": integer,
|
||||
"transferSx": integer,
|
||||
"persistentKeepalive": integer,
|
||||
"allowedIps": [string]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ wg show all dump | jc --wg-show -p
|
||||
[
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "aEbVdvHSEp3oofHDNVCsUoaRSxk1Og8/pTLof5yF+1M=",
|
||||
"publicKey": "OIxbQszw1chdO5uigAxpsl4fc/h04yMYafl72gUbakM=",
|
||||
"listenPort": 51820,
|
||||
"fwmark": null,
|
||||
"peers": {
|
||||
"sQFGAhSdx0aC7DmTFojzBOW8Ccjv1XV5+N9FnkZu5zc=": {
|
||||
"presharedKey": null,
|
||||
"endpoint": "79.134.136.199:40036",
|
||||
"latestHandshake": 1728809756,
|
||||
"transferRx": 1378724,
|
||||
"transferSx": 406524,
|
||||
"persistentKeepalive": null,
|
||||
"allowedIps": ["10.10.0.2/32"]
|
||||
},
|
||||
"B9csmpvrv4Q7gpjc6zAbNNO8hIOYfpBqxmik2aNpwwE=": {
|
||||
"presharedKey": null,
|
||||
"endpoint": "79.134.136.199:35946",
|
||||
"latestHandshake": 1728809756,
|
||||
"transferRx": 4884248,
|
||||
"transferSx": 3544596,
|
||||
"persistentKeepalive": null,
|
||||
"allowedIps": ["10.10.0.3/32"]
|
||||
},
|
||||
"miiSYR5UdevREhlWpmnci+vv/dEGLHbNtKu7u1CuOD4=": {
|
||||
"presharedKey": null,
|
||||
"allowedIps": ["10.10.0.4/32"]
|
||||
},
|
||||
"gx9+JHLHJvOfBNjTmZ8KQAnThFFiZMQrX1kRaYcIYzw=": {
|
||||
"presharedKey": null,
|
||||
"endpoint": "173.244.225.194:45014",
|
||||
"latestHandshake": 1728809827,
|
||||
"transferRx": 1363652,
|
||||
"transferSx": 458252,
|
||||
"persistentKeepalive": null,
|
||||
"allowedIps": ["10.10.0.5/32"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
$ wg show all dump | jc --wg-show -p -r
|
||||
[
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "aEbVdvHSEp3oofHDNVCsUoaRSxk1Og8/pTLof5yF+1M=",
|
||||
"publicKey": "OIxbQszw1chdO5uigAxpsl4fc/h04yMYafl72gUbakM=",
|
||||
"listenPort": 51820,
|
||||
"fwmark": null,
|
||||
"peers": {
|
||||
"sQFGAhSdx0aC7DmTFojzBOW8Ccjv1XV5+N9FnkZu5zc=": {
|
||||
"presharedKey": null,
|
||||
"endpoint": "79.134.136.199:40036",
|
||||
"latestHandshake": 1728809756,
|
||||
"transferRx": 1378724,
|
||||
"transferSx": 406524,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": ["10.10.0.2/32"]
|
||||
},
|
||||
"B9csmpvrv4Q7gpjc6zAbNNO8hIOYfpBqxmik2aNpwwE=": {
|
||||
"presharedKey": null,
|
||||
"endpoint": "79.134.136.199:35946",
|
||||
"latestHandshake": 1728809756,
|
||||
"transferRx": 4884248,
|
||||
"transferSx": 3544596,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": ["10.10.0.3/32"]
|
||||
},
|
||||
"miiSYR5UdevREhlWpmnci+vv/dEGLHbNtKu7u1CuOD4=": {
|
||||
"presharedKey": null,
|
||||
"allowedIps": ["10.10.0.4/32"]
|
||||
},
|
||||
"gx9+JHLHJvOfBNjTmZ8KQAnThFFiZMQrX1kRaYcIYzw=": {
|
||||
"presharedKey": null,
|
||||
"endpoint": "173.244.225.194:45014",
|
||||
"latestHandshake": 1728809827,
|
||||
"transferRx": 1363652,
|
||||
"transferSx": 458252,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": ["10.10.0.5/32"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
from typing import List, Dict, Optional, Union
|
||||
from jc.jc_types import JSONDictType
|
||||
import jc.utils
|
||||
import re
|
||||
|
||||
PeerData = Dict[str, Union[Optional[str], Optional[int], List[str]]]
|
||||
DeviceData = Dict[str, Union[Optional[str], Optional[int], Dict[str, PeerData]]]
|
||||
|
||||
|
||||
class info:
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
|
||||
version = "1.0"
|
||||
description = (
|
||||
"Parses the output of the `wg show` command to provide structured JSON data"
|
||||
)
|
||||
author = "Hamza Saht"
|
||||
author_email = "hamzasaht01@gmail.com"
|
||||
compatible = ["linux", "darwin", "cygwin", "win32", "aix", "freebsd"]
|
||||
tags = ["command"]
|
||||
magic_commands = ["wg-show"]
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def _process(proc_data: List[DeviceData]) -> List[JSONDictType]:
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (List[Dict]) Raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List[Dict]: Structured data that conforms to the schema
|
||||
"""
|
||||
processed_data: List[JSONDictType] = []
|
||||
for device in proc_data:
|
||||
processed_device = {
|
||||
"device": device["device"],
|
||||
"privateKey": device.get("privateKey"),
|
||||
"publicKey": device.get("publicKey"),
|
||||
"listenPort": device.get("listenPort"),
|
||||
"fwmark": device.get("fwmark"),
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": peer_key,
|
||||
"presharedKey": peer_data.get("presharedKey"),
|
||||
"endpoint": peer_data.get("endpoint"),
|
||||
"latestHandshake": peer_data.get("latestHandshake", 0),
|
||||
"transferRx": peer_data.get("transferRx", 0),
|
||||
"transferSx": peer_data.get("transferSx", 0),
|
||||
"persistentKeepalive": peer_data.get("persistentKeepalive", -1),
|
||||
"allowedIps": peer_data.get("allowedIps", []),
|
||||
}
|
||||
for peer_key, peer_data in device.get("peers", {}).items()
|
||||
],
|
||||
}
|
||||
processed_data.append(processed_device)
|
||||
return processed_data
|
||||
|
||||
|
||||
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[DeviceData]:
|
||||
"""
|
||||
Main text parsing function.
|
||||
|
||||
Parses the output of the `wg` command, specifically `wg show all dump`, into structured JSON format.
|
||||
|
||||
Parameters:
|
||||
|
||||
data: (str) Text data to parse, typically the output from `wg show all dump`
|
||||
raw: (bool) If True, returns unprocessed output
|
||||
quiet: (bool) Suppress warning messages if True
|
||||
|
||||
Returns:
|
||||
|
||||
List[Dict]: Parsed data in JSON-friendly format, either raw or processed.
|
||||
"""
|
||||
jc.utils.compatibility(__name__, info.compatible, quiet)
|
||||
jc.utils.input_type_check(data)
|
||||
|
||||
raw_output: List[DeviceData] = []
|
||||
current_device: Optional[str] = None
|
||||
device_data: DeviceData = {}
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
for line in filter(None, data.splitlines()):
|
||||
fields = re.split(r"\s+", line.strip())
|
||||
if len(fields) == 5:
|
||||
device, private_key, public_key, listen_port, fwmark = fields
|
||||
if current_device:
|
||||
raw_output.append({"device": current_device, **device_data})
|
||||
current_device = device
|
||||
device_data = {
|
||||
"privateKey": private_key if private_key != "(none)" else None,
|
||||
"publicKey": public_key if public_key != "(none)" else None,
|
||||
"listenPort": int(listen_port) if listen_port != "0" else None,
|
||||
"fwmark": int(fwmark) if fwmark != "off" else None,
|
||||
"peers": {},
|
||||
}
|
||||
elif len(fields) == 9:
|
||||
(
|
||||
interface,
|
||||
public_key,
|
||||
preshared_key,
|
||||
endpoint,
|
||||
allowed_ips,
|
||||
latest_handshake,
|
||||
transfer_rx,
|
||||
transfer_tx,
|
||||
persistent_keepalive,
|
||||
) = fields
|
||||
peer_data: PeerData = {
|
||||
"presharedKey": preshared_key
|
||||
if preshared_key != "(none)"
|
||||
else None,
|
||||
"endpoint": endpoint if endpoint != "(none)" else None,
|
||||
"latestHandshake": int(latest_handshake),
|
||||
"transferRx": int(transfer_rx),
|
||||
"transferSx": int(transfer_tx),
|
||||
"persistentKeepalive": int(persistent_keepalive)
|
||||
if persistent_keepalive != "off"
|
||||
else -1,
|
||||
"allowedIps": allowed_ips.split(",")
|
||||
if allowed_ips != "(none)"
|
||||
else [],
|
||||
}
|
||||
device_data["peers"][public_key] = {
|
||||
k: v for k, v in peer_data.items() if v is not None
|
||||
}
|
||||
|
||||
if current_device:
|
||||
raw_output.append({"device": current_device, **device_data})
|
||||
|
||||
return raw_output if raw else _process(raw_output)
|
95
tests/fixtures/ubuntu-22.04/wg_show--one_device.json
vendored
Normal file
95
tests/fixtures/ubuntu-22.04/wg_show--one_device.json
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
[
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "ZkG2dvJSUq5ohkDFNWBqToaVSyk4Pp8/bULaf6yX+3N=",
|
||||
"publicKey": "PQsbRs4w2fidQ7uhjgCypl5fc/804bHZbfl83gGvakN=",
|
||||
"listenPort": 51820,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "rQFRAjRdx1aD8DnTFpkcBOY9Edjt3ZU7+P9HokZv7xe=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:50024",
|
||||
"latestHandshake": 1829439251,
|
||||
"transferRx": 1536642,
|
||||
"transferSx": 492320,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.2/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "A0fsnrwsv7S9hrk8yzCgOON9gKPYfpCrzqil4bPpxAE=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:49732",
|
||||
"latestHandshake": 1829439125,
|
||||
"transferRx": 5641359,
|
||||
"transferSx": 4206783,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.3/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "pkjVZR5VdfnSFhlWsqnkf+wv/eHGLHzOtKu8v2CvOD5=",
|
||||
"presharedKey": null,
|
||||
"endpoint": null,
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 0,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.4/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "hz0+KJRHJyXfDNjUnZ9LRAnShFFjZNTrW2jRbXjIazx=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "180.255.226.203:21678",
|
||||
"latestHandshake": 1829439243,
|
||||
"transferRx": 1555523,
|
||||
"transferSx": 544780,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.5/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "kujr4Z8eutQ8ebzFf33DLc3PNKrO3J+ZVy3jkrR1cUZ=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:67130",
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 0,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.6/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "XcgkMRmxhQiIgXowYqsxUt1SlwUydXJd4Zmi8dgGeYe=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "180.255.226.203:56092",
|
||||
"latestHandshake": 1829439121,
|
||||
"transferRx": 1900247,
|
||||
"transferSx": 1352639,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.8/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "tB9yFqLmyvcDD1rJ1rTgeKtKK98hdUL1jefMRt4XbDh=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:60184",
|
||||
"latestHandshake": 1829037182,
|
||||
"transferRx": 75047,
|
||||
"transferSx": 184725,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.7/32"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
9
tests/fixtures/ubuntu-22.04/wg_show--one_device.out
vendored
Normal file
9
tests/fixtures/ubuntu-22.04/wg_show--one_device.out
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
wg0 ZkG2dvJSUq5ohkDFNWBqToaVSyk4Pp8/bULaf6yX+3N= PQsbRs4w2fidQ7uhjgCypl5fc/804bHZbfl83gGvakN= 51820 off
|
||||
wg0 rQFRAjRdx1aD8DnTFpkcBOY9Edjt3ZU7+P9HokZv7xe= (none) 82.132.137.204:50024 10.10.0.2/32 1829439251 1536642 492320 off
|
||||
wg0 A0fsnrwsv7S9hrk8yzCgOON9gKPYfpCrzqil4bPpxAE= (none) 82.132.137.204:49732 10.10.0.3/32 1829439125 5641359 4206783 off
|
||||
wg0 pkjVZR5VdfnSFhlWsqnkf+wv/eHGLHzOtKu8v2CvOD5= (none) (none) 10.10.0.4/32 0 0 0 off
|
||||
wg0 hz0+KJRHJyXfDNjUnZ9LRAnShFFjZNTrW2jRbXjIazx= (none) 180.255.226.203:21678 10.10.0.5/32 1829439243 1555523 544780 off
|
||||
wg0 kujr4Z8eutQ8ebzFf33DLc3PNKrO3J+ZVy3jkrR1cUZ= (none) 82.132.137.204:67130 10.10.0.6/32 0 0 0 off
|
||||
wg0 XcgkMRmxhQiIgXowYqsxUt1SlwUydXJd4Zmi8dgGeYe= (none) 180.255.226.203:56092 10.10.0.8/32 1829439121 1900247 1352639 off
|
||||
wg0 tB9yFqLmyvcDD1rJ1rTgeKtKK98hdUL1jefMRt4XbDh= (none) 82.132.137.204:60184 10.10.0.7/32 1829037182 75047 184725 off
|
||||
|
245
tests/fixtures/ubuntu-22.04/wg_show--two_devices.json
vendored
Normal file
245
tests/fixtures/ubuntu-22.04/wg_show--two_devices.json
vendored
Normal file
@ -0,0 +1,245 @@
|
||||
[
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "ZkG2dvJSUq5ohkDFNWBqToaVSyk4Pp8/bULaf6yX+3N=",
|
||||
"publicKey": "PQsbRs4w2fidQ7uhjgCypl5fc/804bHZbfl83gGvakN=",
|
||||
"listenPort": 51820,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "rQFRAjRdx1aD8DnTFpkcBOY9Edjt3ZU7+P9HokZv7xe=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:50024",
|
||||
"latestHandshake": 1829439251,
|
||||
"transferRx": 1536642,
|
||||
"transferSx": 492320,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.2/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "A0fsnrwsv7S9hrk8yzCgOON9gKPYfpCrzqil4bPpxAE=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:49732",
|
||||
"latestHandshake": 1829439125,
|
||||
"transferRx": 5641359,
|
||||
"transferSx": 4206783,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.3/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "pkjVZR5VdfnSFhlWsqnkf+wv/eHGLHzOtKu8v2CvOD5=",
|
||||
"presharedKey": null,
|
||||
"endpoint": null,
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 0,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.4/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "hz0+KJRHJyXfDNjUnZ9LRAnShFFjZNTrW2jRbXjIazx=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "180.255.226.203:21678",
|
||||
"latestHandshake": 1829439243,
|
||||
"transferRx": 1555523,
|
||||
"transferSx": 544780,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.5/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "kujr4Z8eutQ8ebzFf33DLc3PNKrO3J+ZVy3jkrR1cUZ=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:67130",
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 0,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.6/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "XcgkMRmxhQiIgXowYqsxUt1SlwUydXJd4Zmi8dgGeYe=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "180.255.226.203:56092",
|
||||
"latestHandshake": 1829439121,
|
||||
"transferRx": 1900247,
|
||||
"transferSx": 1352639,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.8/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "tB9yFqLmyvcDD1rJ1rTgeKtKK98hdUL1jefMRt4XbDh=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "82.132.137.204:60184",
|
||||
"latestHandshake": 1829037182,
|
||||
"transferRx": 75047,
|
||||
"transferSx": 184725,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.7/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "JH8Fz8KGH5vDYu3eUuWwRcTUcvRqFHZfMlNtsg2xZwF=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "91.142.150.210:51478",
|
||||
"latestHandshake": 1829037123,
|
||||
"transferRx": 985632,
|
||||
"transferSx": 723582,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.9/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "Yx6kNq8xhPmKhYq0YqTxVt2ZmxZvdYKg5Ymj9fgHkGh=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "92.233.144.193:61112",
|
||||
"latestHandshake": 1829037212,
|
||||
"transferRx": 1350235,
|
||||
"transferSx": 945301,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.0.10/32"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"device": "wg1",
|
||||
"privateKey": "JnR8bwIHKq7yqfNDOWBlTohSTxl7Wa9/sTLcf6tQ+4O=",
|
||||
"publicKey": "MUocVr6x4gjhT9vkkDrzm6hc/906dJHYcgk93iHvbmR=",
|
||||
"listenPort": 51821,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "yQHRBjVgy2fC9EkUFlhdDPZ0Lekv4YM9+Q0GmnXw9gf=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "72.144.138.212:50135",
|
||||
"latestHandshake": 1929850372,
|
||||
"transferRx": 1678923,
|
||||
"transferSx": 513470,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.2/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "C1gsotwrx9S9jsq9yzJgPPO0hNRYgrDsblmj6dSrkZE=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "59.232.145.213:49364",
|
||||
"latestHandshake": 1929850156,
|
||||
"transferRx": 5982563,
|
||||
"transferSx": 4378204,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.3/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "qjkYZR6WfgnTGjnXrqokf+xw/fIFMHyPtLu9w3DwOF6=",
|
||||
"presharedKey": null,
|
||||
"endpoint": null,
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 0,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.4/32"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"device": "wg1",
|
||||
"privateKey": "JpK6HvHKLp9zmqDFQXBqUmxTSvW6Vp9/zTLbf6pT+7N=",
|
||||
"publicKey": "LQdcXs5y5dkgU0vmkCszm8hf/907fKHYdhk94jHvbnQ=",
|
||||
"listenPort": 51821,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "tRFGGjUhy3hD0GmVEljeDQY0Mhlv5YM7+Q2HmnWy9je=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "69.157.149.222:51049",
|
||||
"latestHandshake": 1929851223,
|
||||
"transferRx": 1680921,
|
||||
"transferSx": 523451,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.5/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "K2hzotyrx8S1jsq0yzHgTQO1kOYVhrDwblmj7eTrkZF=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "61.242.155.214:48012",
|
||||
"latestHandshake": 1929851045,
|
||||
"transferRx": 6052145,
|
||||
"transferSx": 4435280,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.6/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "VliYZS7WggpUFkWNralkg+wz/eIHMHyStMpu0x4EoEJ=",
|
||||
"presharedKey": null,
|
||||
"endpoint": null,
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 0,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.7/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "kB8yFrKmyvaDF1uL2uUgeOsLL99jeUL2kefKRt3ZoFh=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "72.132.145.206:62084",
|
||||
"latestHandshake": 1929137285,
|
||||
"transferRx": 95023,
|
||||
"transferSx": 197982,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.8/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "Z9fsqvwty8U9jqj1zyKgPRQ1hOXYgrFtcmli8fSprHF=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "68.243.154.222:54321",
|
||||
"latestHandshake": 1929137125,
|
||||
"transferRx": 1200475,
|
||||
"transferSx": 890678,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.9/32"
|
||||
]
|
||||
},
|
||||
{
|
||||
"publicKey": "Lx9lNq9xhPnJhYr1YqYxVt3ZmyawdZLg5Zmj0fhGlJk=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "71.233.144.204:59012",
|
||||
"latestHandshake": 1929137243,
|
||||
"transferRx": 1450234,
|
||||
"transferSx": 1006235,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.10.1.10/32"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
22
tests/fixtures/ubuntu-22.04/wg_show--two_devices.out
vendored
Normal file
22
tests/fixtures/ubuntu-22.04/wg_show--two_devices.out
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
wg0 ZkG2dvJSUq5ohkDFNWBqToaVSyk4Pp8/bULaf6yX+3N= PQsbRs4w2fidQ7uhjgCypl5fc/804bHZbfl83gGvakN= 51820 off
|
||||
wg0 rQFRAjRdx1aD8DnTFpkcBOY9Edjt3ZU7+P9HokZv7xe= (none) 82.132.137.204:50024 10.10.0.2/32 1829439251 1536642 492320 off
|
||||
wg0 A0fsnrwsv7S9hrk8yzCgOON9gKPYfpCrzqil4bPpxAE= (none) 82.132.137.204:49732 10.10.0.3/32 1829439125 5641359 4206783 off
|
||||
wg0 pkjVZR5VdfnSFhlWsqnkf+wv/eHGLHzOtKu8v2CvOD5= (none) (none) 10.10.0.4/32 0 0 0 off
|
||||
wg0 hz0+KJRHJyXfDNjUnZ9LRAnShFFjZNTrW2jRbXjIazx= (none) 180.255.226.203:21678 10.10.0.5/32 1829439243 1555523 544780 off
|
||||
wg0 kujr4Z8eutQ8ebzFf33DLc3PNKrO3J+ZVy3jkrR1cUZ= (none) 82.132.137.204:67130 10.10.0.6/32 0 0 0 off
|
||||
wg0 XcgkMRmxhQiIgXowYqsxUt1SlwUydXJd4Zmi8dgGeYe= (none) 180.255.226.203:56092 10.10.0.8/32 1829439121 1900247 1352639 off
|
||||
wg0 tB9yFqLmyvcDD1rJ1rTgeKtKK98hdUL1jefMRt4XbDh= (none) 82.132.137.204:60184 10.10.0.7/32 1829037182 75047 184725 off
|
||||
wg0 JH8Fz8KGH5vDYu3eUuWwRcTUcvRqFHZfMlNtsg2xZwF= (none) 91.142.150.210:51478 10.10.0.9/32 1829037123 985632 723582 off
|
||||
wg0 Yx6kNq8xhPmKhYq0YqTxVt2ZmxZvdYKg5Ymj9fgHkGh= (none) 92.233.144.193:61112 10.10.0.10/32 1829037212 1350235 945301 off
|
||||
wg1 JnR8bwIHKq7yqfNDOWBlTohSTxl7Wa9/sTLcf6tQ+4O= MUocVr6x4gjhT9vkkDrzm6hc/906dJHYcgk93iHvbmR= 51821 off
|
||||
wg1 yQHRBjVgy2fC9EkUFlhdDPZ0Lekv4YM9+Q0GmnXw9gf= (none) 72.144.138.212:50135 10.10.1.2/32 1929850372 1678923 513470 off
|
||||
wg1 C1gsotwrx9S9jsq9yzJgPPO0hNRYgrDsblmj6dSrkZE= (none) 59.232.145.213:49364 10.10.1.3/32 1929850156 5982563 4378204 off
|
||||
wg1 qjkYZR6WfgnTGjnXrqokf+xw/fIFMHyPtLu9w3DwOF6= (none) (none) 10.10.1.4/32 0 0 0 off
|
||||
wg1 JpK6HvHKLp9zmqDFQXBqUmxTSvW6Vp9/zTLbf6pT+7N= LQdcXs5y5dkgU0vmkCszm8hf/907fKHYdhk94jHvbnQ= 51821 off
|
||||
wg1 tRFGGjUhy3hD0GmVEljeDQY0Mhlv5YM7+Q2HmnWy9je= (none) 69.157.149.222:51049 10.10.1.5/32 1929851223 1680921 523451 off
|
||||
wg1 K2hzotyrx8S1jsq0yzHgTQO1kOYVhrDwblmj7eTrkZF= (none) 61.242.155.214:48012 10.10.1.6/32 1929851045 6052145 4435280 off
|
||||
wg1 VliYZS7WggpUFkWNralkg+wz/eIHMHyStMpu0x4EoEJ= (none) (none) 10.10.1.7/32 0 0 0 off
|
||||
wg1 kB8yFrKmyvaDF1uL2uUgeOsLL99jeUL2kefKRt3ZoFh= (none) 72.132.145.206:62084 10.10.1.8/32 1929137285 95023 197982 off
|
||||
wg1 Z9fsqvwty8U9jqj1zyKgPRQ1hOXYgrFtcmli8fSprHF= (none) 68.243.154.222:54321 10.10.1.9/32 1929137125 1200475 890678 off
|
||||
wg1 Lx9lNq9xhPnJhYr1YqYxVt3ZmyawdZLg5Zmj0fhGlJk= (none) 71.233.144.204:59012 10.10.1.10/32 1929137243 1450234 1006235 off
|
||||
|
94
tests/fixtures/windows/windows-10/wg_show.json
vendored
Normal file
94
tests/fixtures/windows/windows-10/wg_show.json
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
[
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "Xa4Bq8AUFrjKp+Z283VDzEUVeOOn2wX/uuLTMUkkJens=",
|
||||
"publicKey": "mL2Co/VecYWtXSY6YUZAI6cAsFZDCEV+9iZKibNcWTu=",
|
||||
"listenPort": 45321,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "bN9QoMEqlKUpncq0Q8ye9yURczKwmbXzwVsG7A+RV2B=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "123.45.67.89:51820",
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 1532,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"0.0.0.0/0"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "yJ3PoNAqlNUpmcq0P7xv8zURdyKwmbZwwUsG9B+SV3C=",
|
||||
"publicKey": "kP2Lo/WfgVWtYSY7ZUZAJ7cBsEZECFV+8jYKidOcVTv=",
|
||||
"listenPort": 53211,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "dQ5AoNAqpOUlncq0P9ze8xURayLwmbYwwVsH8C+TV4D=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "203.0.113.4:51820",
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 2001,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"192.168.1.0/24"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "pR6DoOBqmNUlncq0P1wq9zUSeyJwmbVxxWsF7D+RU5E=",
|
||||
"publicKey": "qN2Mo/XghWWtXSY8YVZBK8cDsFZDCFQ+7kZKjbNcWTx=",
|
||||
"listenPort": 67514,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "tA8AoPCqoPUlncq0P8xe7xUSayKwmbWxxVsG8E+UV6F=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "198.51.100.15:51820",
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 1403,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"10.0.0.0/8"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "zU9CoQCqmQUlncq0P4wo6yUTbyJwmbYyyWsF9F+SV7G=",
|
||||
"publicKey": "vM2Ko/YigXWtYSY9YUZCJ9dCsGZECFV+5lZLjcOcVVy=",
|
||||
"listenPort": 79812,
|
||||
"fwmark": null,
|
||||
"peers": [
|
||||
{
|
||||
"publicKey": "xC7DoRDqnRUlncq0P2wq9yUScyKwmbXzyWsH8F+TU8H=",
|
||||
"presharedKey": null,
|
||||
"endpoint": "172.16.0.1:51820",
|
||||
"latestHandshake": 0,
|
||||
"transferRx": 0,
|
||||
"transferSx": 1872,
|
||||
"persistentKeepalive": -1,
|
||||
"allowedIps": [
|
||||
"172.16.0.0/16"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"device": "wg0",
|
||||
"privateKey": "rE4AoSCqnSUlncq0P7wv9zURdyLwmbZxzWsG9G+UV9I=",
|
||||
"publicKey": "fN2Oo/ZjhYUtXSZ0YUZDK8eDsFZDCFQ+4jYKjcNcVVw=",
|
||||
"listenPort": 91114,
|
||||
"fwmark": null,
|
||||
"peers": []
|
||||
}
|
||||
]
|
9
tests/fixtures/windows/windows-10/wg_show.out
vendored
Normal file
9
tests/fixtures/windows/windows-10/wg_show.out
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
wg0 Xa4Bq8AUFrjKp+Z283VDzEUVeOOn2wX/uuLTMUkkJens= mL2Co/VecYWtXSY6YUZAI6cAsFZDCEV+9iZKibNcWTu= 45321 off
|
||||
wg0 bN9QoMEqlKUpncq0Q8ye9yURczKwmbXzwVsG7A+RV2B= (none) 123.45.67.89:51820 0.0.0.0/0 0 0 1532 off
|
||||
wg0 yJ3PoNAqlNUpmcq0P7xv8zURdyKwmbZwwUsG9B+SV3C= kP2Lo/WfgVWtYSY7ZUZAJ7cBsEZECFV+8jYKidOcVTv= 53211 off
|
||||
wg0 dQ5AoNAqpOUlncq0P9ze8xURayLwmbYwwVsH8C+TV4D= (none) 203.0.113.4:51820 192.168.1.0/24 0 0 2001 off
|
||||
wg0 pR6DoOBqmNUlncq0P1wq9zUSeyJwmbVxxWsF7D+RU5E= qN2Mo/XghWWtXSY8YVZBK8cDsFZDCFQ+7kZKjbNcWTx= 67514 off
|
||||
wg0 tA8AoPCqoPUlncq0P8xe7xUSayKwmbWxxVsG8E+UV6F= (none) 198.51.100.15:51820 10.0.0.0/8 0 0 1403 off
|
||||
wg0 zU9CoQCqmQUlncq0P4wo6yUTbyJwmbYyyWsF9F+SV7G= vM2Ko/YigXWtYSY9YUZCJ9dCsGZECFV+5lZLjcOcVVy= 79812 off
|
||||
wg0 xC7DoRDqnRUlncq0P2wq9yUScyKwmbXzyWsH8F+TU8H= (none) 172.16.0.1:51820 172.16.0.0/16 0 0 1872 off
|
||||
wg0 rE4AoSCqnSUlncq0P7wv9zURdyLwmbZxzWsG9G+UV9I= fN2Oo/ZjhYUtXSZ0YUZDK8eDsFZDCFQ+4jYKjcNcVVw= 91114 off
|
26
tests/test_wg_show.py
Normal file
26
tests/test_wg_show.py
Normal file
@ -0,0 +1,26 @@
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd())
|
||||
from tests import utils_for_test as test_utils
|
||||
|
||||
sys.path.pop()
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
def test_wg_show_nodata(self):
|
||||
"""
|
||||
Test 'wg-show' with no data
|
||||
"""
|
||||
test_utils.run_no_data(self, __file__, [])
|
||||
|
||||
def test_wg_show_all_fixtures(self):
|
||||
"""
|
||||
Test 'wg-show' with various fixtures
|
||||
"""
|
||||
test_utils.run_all_fixtures(self, __file__)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Reference in New Issue
Block a user