Updated geoip to check history before doing lookup
This commit is contained in:
parent
39c5196349
commit
512f94d7f6
1 changed files with 59 additions and 35 deletions
94
log.py
94
log.py
|
@ -108,45 +108,69 @@ class logsManager:
|
|||
|
||||
try:
|
||||
|
||||
if 'delayUntil' in locals() and datetime.now() < delayUntil:
|
||||
|
||||
print("Rate limit exceeded. Please wait before trying again.")
|
||||
return None
|
||||
conn = pyodbc.connect(self.conn_str)
|
||||
cursor = conn.cursor()
|
||||
timeThreshold = datetime.now() - timedelta(days=1)
|
||||
|
||||
url = f"https://ipinfo.io/{ip}?token={token}"
|
||||
cursor.execute("SELECT blockedipaddress, hostname, city, region, country, loc, org, postal, timezone FROM monutil_geoip WHERE logtime >= ?", timeThreshold)
|
||||
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
if response.status_code == 429:
|
||||
|
||||
print("Rate limit exceeded. Please wait before trying again.")
|
||||
today = datetime.now()
|
||||
|
||||
if today.month == 12:
|
||||
|
||||
delayUntil = datetime(today.year + 1, 1, 1)
|
||||
|
||||
else:
|
||||
|
||||
delayUntil = datetime(today.year, today.month + 1, 1)
|
||||
|
||||
return None
|
||||
|
||||
geoinfo = {
|
||||
"ip": data.get("ip"),
|
||||
"hostname": data.get("hostname"),
|
||||
"city": data.get("city"),
|
||||
"region": data.get("region"),
|
||||
"country": data.get("country"),
|
||||
"loc": data.get("loc"),
|
||||
"org": data.get("org"),
|
||||
"postal": data.get("postal"),
|
||||
"timezone": data.get("timezone"),
|
||||
}
|
||||
rows = cursor.fetchall()
|
||||
|
||||
geoinfo = []
|
||||
|
||||
for row in rows:
|
||||
geoinfo = {
|
||||
"ip": row.blockedipaddress,
|
||||
"hostname": row.hostname,
|
||||
"city": row.city,
|
||||
"region": row.region,
|
||||
"country": row.country,
|
||||
"loc": row.loc,
|
||||
"org": row.org,
|
||||
"postal": row.postal,
|
||||
"timezone": row.timezone,
|
||||
}
|
||||
|
||||
if not geoinfo:
|
||||
|
||||
if 'delayUntil' in locals() and datetime.now() < delayUntil:
|
||||
|
||||
print("Rate limit exceeded. Please wait before trying again.")
|
||||
return None
|
||||
|
||||
url = f"https://ipinfo.io/{ip}?token={token}"
|
||||
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
if response.status_code == 429:
|
||||
|
||||
print("Rate limit exceeded. Please wait before trying again.")
|
||||
today = datetime.now()
|
||||
|
||||
if today.month == 12:
|
||||
|
||||
delayUntil = datetime(today.year + 1, 1, 1)
|
||||
|
||||
else:
|
||||
|
||||
delayUntil = datetime(today.year, today.month + 1, 1)
|
||||
|
||||
return None
|
||||
|
||||
geoinfo = {
|
||||
"ip": data.get("ip"),
|
||||
"hostname": data.get("hostname"),
|
||||
"city": data.get("city"),
|
||||
"region": data.get("region"),
|
||||
"country": data.get("country"),
|
||||
"loc": data.get("loc"),
|
||||
"org": data.get("org"),
|
||||
"postal": data.get("postal"),
|
||||
"timezone": data.get("timezone"),
|
||||
}
|
||||
|
||||
return geoinfo
|
||||
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in a new issue