MCPcopy Create free account
hub / github.com/Vinyzu/Botright / check_proxy

Method check_proxy

botright/modules/proxy_manager.py:106–150  ·  view source on GitHub ↗

Check the validity of the proxy by making HTTP requests to determine its properties. Args: httpx_client (httpx.AsyncClient): The HTTPX client to use for proxy checks.

(self, httpx_client: httpx.AsyncClient)

Source from the content-addressed store, hash-verified

104 raise SplitError(f"Proxy Format ({self.proxy}) isnt supported")
105
106 async def check_proxy(self, httpx_client: httpx.AsyncClient) -> None:
107 """
108 Check the validity of the proxy by making HTTP requests to determine its properties.
109
110 Args:
111 httpx_client (httpx.AsyncClient): The HTTPX client to use for proxy checks.
112 """
113 get_ip_apis = ["https://api.ipify.org/?format=json", "https://api.myip.com/", "https://get.geojs.io/v1/ip.json", "https://api.ip.sb/jsonip", "https://l2.io/ip.json"]
114
115 for get_ip_api in get_ip_apis:
116 try:
117 ip_request = await httpx_client.get(get_ip_api, timeout=self.timeout)
118 ip = ip_request.json().get("ip")
119 break
120 except Exception:
121 pass
122 else:
123 raise ProxyCheckError("Could not get IP-Address of Proxy (Proxy is Invalid/Timed Out)")
124
125 get_geo_apis = {
126 "http://ip-api.com/json/<IP>": ["country", "countryCode", "lat", "lon", "timezone"],
127 "https://ipapi.co/<IP>/json": ["country_name", "country", "latitude", "longitude", "timezone"],
128 "https://api.techniknews.net/ipgeo/<IP>": ["country", "countryCode", "lat", "lon", "timezone"],
129 "https://get.geojs.io/v1/ip/geo/<IP>.json": ["country", "country_code", "latitude", "longitude", "timezone"],
130 }
131
132 for get_geo_api, api_names in get_geo_apis.items():
133 try:
134 api_url = get_geo_api.replace("<IP>", ip)
135 country, country_code, latitude, longitude, timezone = api_names
136 r = await self._httpx.get(api_url, timeout=self.timeout)
137 data = r.json()
138
139 self.country = data.get(country)
140 self.country_code = data.get(country_code)
141 self.latitude = data.get(latitude)
142 self.longitude = data.get(longitude)
143 self.timezone = data.get(timezone)
144
145 assert self.country
146 break
147 except Exception:
148 pass
149 else:
150 raise ProxyCheckError("Could not get GeoInformation from proxy (Proxy is probably not Indexed)")

Callers 1

__ainit__Method · 0.95

Calls 1

ProxyCheckErrorClass · 0.85

Tested by

no test coverage detected