-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_local.py
More file actions
50 lines (42 loc) · 1.4 KB
/
logger_local.py
File metadata and controls
50 lines (42 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# logger_local.py
# Small helper to read/write the hacker diary JSON (safe local version)
import json
import os
from datetime import datetime
BASE_DIR = os.path.dirname(__file__)
DATA_PATH = os.path.join(BASE_DIR, "Showcase_Demo.json")
def ensure_file():
if not os.path.exists(DATA_PATH):
with open(DATA_PATH, "w") as f:
json.dump([], f)
def append_entry(entry:dict):
"""Append a new handshake record to the diary."""
ensure_file()
with open(DATA_PATH, "r+", encoding="utf-8") as f:
try:
data = json.load(f)
except json.JSONDecodeError:
data = []
if "timestamp" not in entry:
entry["timestamp"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if "eapol_count" not in entry:
entry["eapol_count"] = 0
if "essid" not in entry:
entry["essid"] = "<unknown>"
if "bssid" not in entry:
entry["bssid"] = None
data.append(entry)
f.seek(0)
json.dump(data, f, indent=2)
f.truncate()
return entry
def read_all():
ensure_file()
with open(DATA_PATH, "r", encoding="utf-8") as f:
try:
return json.load(f)
except json.JSONDecodeError:
return []
def clear():
with open(DATA_PATH, "w", encoding="utf-8") as f:
json.dump([], f)