mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Add timeout to proxy checker
This commit is contained in:
parent
2016f1faa3
commit
0f5e7b85b4
1 changed files with 11 additions and 5 deletions
|
@ -897,14 +897,14 @@ class OtherCog(commands.Cog):
|
||||||
await ctx.respond("Removed domain from blacklist.")
|
await ctx.respond("Removed domain from blacklist.")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def check_proxy(url: str = "socks5://localhost:1090"):
|
async def check_proxy(url: str = "socks5://localhost:1090", *, timeout: float = 3.0):
|
||||||
client = httpx.AsyncClient(http2=True, timeout=3)
|
client = httpx.AsyncClient(http2=True, timeout=timeout)
|
||||||
my_ip4 = (await client.get("https://api.ipify.org")).text
|
my_ip4 = (await client.get("https://api.ipify.org")).text
|
||||||
real_ips = [my_ip4]
|
real_ips = [my_ip4]
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
|
|
||||||
# Check the proxy
|
# Check the proxy
|
||||||
client = httpx.AsyncClient(http2=True, proxies=url, timeout=3)
|
client = httpx.AsyncClient(http2=True, proxies=url, timeout=timeout)
|
||||||
try:
|
try:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
"https://1.1.1.1/cdn-cgi/trace",
|
"https://1.1.1.1/cdn-cgi/trace",
|
||||||
|
@ -2356,7 +2356,10 @@ class OtherCog(commands.Cog):
|
||||||
for proxy_uri in results.keys():
|
for proxy_uri in results.keys():
|
||||||
name = results[proxy_uri]["name"]
|
name = results[proxy_uri]["name"]
|
||||||
try:
|
try:
|
||||||
proxy_down = await self.check_proxy("socks5://" + proxy_uri)
|
proxy_down = await asyncio.wait_for(
|
||||||
|
self.check_proxy("socks5://" + proxy_uri),
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
results[proxy_uri]["tested"] = True
|
results[proxy_uri]["tested"] = True
|
||||||
if proxy_down > 0:
|
if proxy_down > 0:
|
||||||
embed.colour = discord.Colour.red()
|
embed.colour = discord.Colour.red()
|
||||||
|
@ -2369,10 +2372,13 @@ class OtherCog(commands.Cog):
|
||||||
else:
|
else:
|
||||||
embed.colour = discord.Colour.green()
|
embed.colour = discord.Colour.green()
|
||||||
break
|
break
|
||||||
|
except asyncio.TimeoutError as e:
|
||||||
|
results[proxy_uri]["failure"] = f"Proxy connection timed out, likely offline. {e}"
|
||||||
|
results[proxy_uri]["tested"] = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
embed.colour = discord.Colour.red()
|
embed.colour = discord.Colour.red()
|
||||||
results[proxy_uri]["failure"] += f"Failed to check {name} proxy (`{e}`)."
|
results[proxy_uri]["failure"] = f"Failed to check {name} proxy (`{e}`)."
|
||||||
results[proxy_uri]["tested"] = True
|
results[proxy_uri]["tested"] = True
|
||||||
else:
|
else:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
|
|
Loading…
Reference in a new issue