Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

add to log proxy GeoIP info #196

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bot/core/geoip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import requests

def get_geo_info(ip_address):
url = f"http://ipinfo.io/{ip_address}/json"
response = requests.get(url)

if response.status_code == 200:
return response.json()
else:
return None
5 changes: 3 additions & 2 deletions bot/core/tapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from bot.utils.scripts import escape_html, login_in_browser
from bot.exceptions import InvalidSession
from .headers import headers

from .geoip import *

class Tapper:
def __init__(self, tg_client: Client, lock: asyncio.Lock):
Expand Down Expand Up @@ -183,7 +183,8 @@ async def check_proxy(self, http_client: aiohttp.ClientSession, proxy: Proxy) ->
try:
response = await http_client.get(url='https://httpbin.org/ip', timeout=aiohttp.ClientTimeout(5))
ip = (await response.json()).get('origin')
logger.info(f"{self.session_name} | Proxy IP: {ip}")
geo_info = get_geo_info(ip)
logger.info(f"{self.session_name} | Proxy IP: {ip} - {geo_info.get('city')}, {geo_info.get('country')}")
except Exception as error:
logger.error(f"{self.session_name} | Proxy: {proxy} | Error: {escape_html(error)}")

Expand Down