Created
July 24, 2024 20:58
-
-
Save meanother/f51a422e393cdc815d8accb036cc2bb9 to your computer and use it in GitHub Desktop.
Сбор данных по пользователям wg0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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