This commit is contained in:
jonas committed 2026-06-07 22:31:56 +02:00
1 parent fe2745e7f8
commit 018316cefd
1 file changed
+6 -8
+6 -8
View File
@@ -50,7 +50,6 @@ def classify(line):
return None
def geo(db, ip):
print(f"Get location for {ip}")
row = db.execute("SELECT country, lat, lon FROM ip_geo WHERE ip=?", (ip,)).fetchone()
if row:
return row
@@ -67,6 +66,7 @@ def geo(db, ip):
(ip, *data)
)
time.sleep(0.1)
print(f"Get location for {ip} to {data[0]}")
return data
def main():
@@ -92,24 +92,22 @@ def main():
out = subprocess.check_output(cmd, text=True)
lines = out.splitlines()
print(f"Parsing {len(lines)} lines")
added = 0
for line in lines:
result = classify(line)
if not result:
continue
ts, ip, port, user, typ = result
print(f"{typ:18} ip={ip} port={port} user={user}")
db.execute(
"INSERT INTO events VALUES (?, ?, ?, ?, ?)",
(ts, ip, port, user, typ)
)
added += 1
if ip:
geo(db, ip)
db.commit()
# save cursor
@@ -124,8 +122,8 @@ def main():
break
db.close()
print("Done")
print(f"Parsed {len(lines)} lines and added {added} events")
if __name__ == "__main__":
main()
print("All done")