initial version
but working
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding: utf-8
|
||||
|
||||
import geoip2.database
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
reader = geoip2.database.Reader("./dbip-country-lite-2025-02.mmdb")
|
||||
|
||||
try:
|
||||
with sys.stdin as file:
|
||||
for rec in file:
|
||||
try:
|
||||
parts = rec.strip().split(" ")
|
||||
ip = parts[0]
|
||||
from_country = None
|
||||
from_continent = None
|
||||
try:
|
||||
from_continent = reader.country(ip).continent.code
|
||||
from_country = reader.country(ip).country.name
|
||||
except geoip2.errors.AddressNotFoundError:
|
||||
from_country = "Unknown"
|
||||
print("{}|{}|{}".format(from_continent, from_country, "|".join(parts)))
|
||||
except:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
exit(0)
|
||||
except:
|
||||
raise
|
||||
Reference in New Issue
Block a user