Skip to content

Instantly share code, notes, and snippets.

@meanother
Created July 24, 2024 20:58
Show Gist options
  • Save meanother/f51a422e393cdc815d8accb036cc2bb9 to your computer and use it in GitHub Desktop.
Save meanother/f51a422e393cdc815d8accb036cc2bb9 to your computer and use it in GitHub Desktop.
Сбор данных по пользователям wg0
#!/usr/bin/python3
import json
import csv
from pathlib import Path
red_line, end_line = "\033[91m", "\033[0m"
export_path = Path.home()
config_wg0_file = export_path.joinpath(".wg-easy/wg0.json")
header = [
"user_hash",
"name",
"address",
"privateKey",
"publicKey",
"preSharedKey",
"createdAt",
"updatedAt",
"enabled"
]
with open(config_wg0_file, "r") as f:
data = json.loads(f.read())
export_file_name = export_path.joinpath("users.csv")
with open(export_file_name, "w") as f:
w = csv.DictWriter(f, header, delimiter=";")
w.writeheader()
users = data.get("clients")
for k, v in users.items():
user_data = dict()
user_data["user_hash"] = k
user_data.update(v)
w.writerow(user_data)
print(f"{red_line}Total users in server: {len(users)}{end_line}")
print(f"{red_line}Export users success, file name is {export_file_name}{end_line}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment