diff --git a/log.py b/log.py index 5dedf89..d14cb5e 100644 --- a/log.py +++ b/log.py @@ -107,34 +107,59 @@ class logsManager: global delayUntil try: - - 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}" + conn = pyodbc.connect(self.conn_str) + cursor = conn.cursor() + timeThreshold = datetime.now() - timedelta(days=1) + + cursor.execute("SELECT blockedipaddress, monutil_geoip.hostname, city, region, country, loc, org, postal, timezone FROM monutil_geoip INNER JOIN monutil_ipblock ON monutil_geoip.logID = monutil_ipblock.logID WHERE logtime >= ? AND blockedipaddress = ?", timeThreshold, ip) - response = requests.get(url) - response.raise_for_status() - data = response.json() + 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 response.status_code == 429: + if not geoinfo: - print("Rate limit exceeded. Please wait before trying again.") - today = datetime.now() - - if today.month == 12: + if 'delayUntil' in locals() and datetime.now() < delayUntil: - delayUntil = datetime(today.year + 1, 1, 1) - - else: - - delayUntil = datetime(today.year, today.month + 1, 1) - - return None + 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() - geoinfo = { + 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"), @@ -146,7 +171,6 @@ class logsManager: "timezone": data.get("timezone"), } - return geoinfo except Exception as e: