базовая структура проекта создана
This commit is contained in:
0
config.php
Normal file
0
config.php
Normal file
0
db/dns.sqlite
Normal file
0
db/dns.sqlite
Normal file
0
logs/dns_num.log
Normal file
0
logs/dns_num.log
Normal file
29
parser/parse_dns_logs.py
Normal file
29
parser/parse_dns_logs.py
Normal file
@@ -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()
|
||||
6
public/api.php
Normal file
6
public/api.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once '../config.php';
|
||||
$db = new PDO("sqlite:../db/dns.sqlite");
|
||||
|
||||
$topDomains = $db->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);
|
||||
0
public/assets/chart.js
Normal file
0
public/assets/chart.js
Normal file
0
public/index.php
Normal file
0
public/index.php
Normal file
Reference in New Issue
Block a user