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