From c3a7fa53a0ae51b5f3790ec2e5455ce21139cee1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Aug 2025 23:57:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.php | 0 db/dns.sqlite | 0 logs/dns_num.log | 0 parser/parse_dns_logs.py | 29 +++++++++++++++++++++++++++++ public/api.php | 6 ++++++ public/assets/chart.js | 0 public/index.php | 0 7 files changed, 35 insertions(+) create mode 100644 config.php create mode 100644 db/dns.sqlite create mode 100644 logs/dns_num.log create mode 100644 parser/parse_dns_logs.py create mode 100644 public/api.php create mode 100644 public/assets/chart.js create mode 100644 public/index.php diff --git a/config.php b/config.php new file mode 100644 index 0000000..e69de29 diff --git a/db/dns.sqlite b/db/dns.sqlite new file mode 100644 index 0000000..e69de29 diff --git a/logs/dns_num.log b/logs/dns_num.log new file mode 100644 index 0000000..e69de29 diff --git a/parser/parse_dns_logs.py b/parser/parse_dns_logs.py new file mode 100644 index 0000000..7d0a3fa --- /dev/null +++ b/parser/parse_dns_logs.py @@ -0,0 +1,29 @@ +import re, sqlite3, os +from datetime import datetime + +db = sqlite3.connect('../db/dns.sqlite') +db.execute('''CREATE TABLE IF NOT EXISTS logs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + timestamp TEXT, + src_ip TEXT, + qtype TEXT, + domain TEXT +)''') + +pattern = re.compile(r'(\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}).*UDP Rcv (\d+\.\d+\.\d+\.\d+).*Q + +\[.*\] + + (\w+) ([\w\.-]+)\.') + +for filename in os.listdir('../logs'): + if filename.startswith('dns') and filename.endswith('.log'): + with open(f'../logs/{filename}', encoding='utf-8') as f: + for line in f: + match = pattern.search(line) + if match: + ts = datetime.strptime(match.group(1), "%d/%m/%Y %H:%M:%S") + db.execute("INSERT INTO logs (timestamp, src_ip, qtype, domain) VALUES (?, ?, ?, ?)", + (ts.isoformat(), match.group(2), match.group(3), match.group(4))) +db.commit() +db.close() \ No newline at end of file diff --git a/public/api.php b/public/api.php new file mode 100644 index 0000000..8645759 --- /dev/null +++ b/public/api.php @@ -0,0 +1,6 @@ +query("SELECT domain, COUNT(*) as hits FROM logs GROUP BY domain ORDER BY hits DESC LIMIT 10")->fetchAll(PDO::FETCH_ASSOC); +echo json_encode($topDomains); diff --git a/public/assets/chart.js b/public/assets/chart.js new file mode 100644 index 0000000..e69de29 diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..e69de29