GmailTrust commited on
Commit
7a1a6f3
·
verified ·
1 Parent(s): 02f60c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -13,31 +13,31 @@ def check_proxy(proxy):
13
  response = requests.get("http://www.google.com", proxies=proxy_dict, timeout=5)
14
  response_time = (time.time() - start_time) * 1000 # Convert to ms
15
  status = "On"
16
- except:
17
  response_time = 0
18
  status = "Off"
19
 
20
- # Call ip-api.com for country and ISP
21
  try:
22
  ip_info = requests.get(f"http://ip-api.com/json/{address}", timeout=5).json()
23
  country = ip_info.get("country", "Unknown")
24
  isp = ip_info.get("isp", "Unknown")
25
- except:
26
  country = "Unknown"
27
  isp = "Unknown"
28
 
29
  return {"address": address, "port": port, "status": status, "response_time": round(response_time, 2), "protocol": "HTTP", "country": country, "isp": isp}
30
 
31
- def check_proxies_generator(proxy_list):
32
  if not proxy_list:
33
- yield "Please enter a list of proxies!"
34
- return
35
 
36
  proxies = proxy_list.splitlines()
37
- with ThreadPoolExecutor(max_workers=1) as executor: # Single worker to yield one at a time
38
- for result in executor.map(check_proxy, proxies):
39
- yield [result["address"], result["port"], result["status"], result["protocol"], result["country"], result["isp"], result["response_time"]]
40
- time.sleep(0.1) # Small delay to simulate real-time update
 
41
 
42
  def filter_proxies(proxies, status_filter, protocol_filter, country_filter):
43
  if not proxies:
@@ -53,7 +53,7 @@ def filter_proxies(proxies, status_filter, protocol_filter, country_filter):
53
 
54
  # Create Gradio interface
55
  with gr.Blocks(title="Proxy Checker") as demo:
56
- gr.Markdown(f"# Proxy Checker - {datetime(2025, 8, 22, 11, 37).strftime('%I:%M %p, %d/%m/%Y +08')}")
57
 
58
  with gr.Row():
59
  with gr.Column():
@@ -76,7 +76,11 @@ with gr.Blocks(title="Proxy Checker") as demo:
76
 
77
  # Logic for checking
78
  def update_table(proxy_list):
79
- return gr.Dataframe.update(value=check_proxies_generator(proxy_list), every=0.1)
 
 
 
 
80
 
81
  check_button.click(
82
  fn=update_table,
 
13
  response = requests.get("http://www.google.com", proxies=proxy_dict, timeout=5)
14
  response_time = (time.time() - start_time) * 1000 # Convert to ms
15
  status = "On"
16
+ except Exception as e:
17
  response_time = 0
18
  status = "Off"
19
 
20
+ # Call ip-api.com for country and ISP with error handling
21
  try:
22
  ip_info = requests.get(f"http://ip-api.com/json/{address}", timeout=5).json()
23
  country = ip_info.get("country", "Unknown")
24
  isp = ip_info.get("isp", "Unknown")
25
+ except Exception as e:
26
  country = "Unknown"
27
  isp = "Unknown"
28
 
29
  return {"address": address, "port": port, "status": status, "response_time": round(response_time, 2), "protocol": "HTTP", "country": country, "isp": isp}
30
 
31
+ def check_proxies(proxy_list):
32
  if not proxy_list:
33
+ return [["No proxies provided", "", "", "", "", "", 0]]
 
34
 
35
  proxies = proxy_list.splitlines()
36
+ results = []
37
+ with ThreadPoolExecutor(max_workers=5) as executor: # Increased workers for better performance
38
+ results = list(executor.map(check_proxy, proxies))
39
+
40
+ return [[r["address"], r["port"], r["status"], r["protocol"], r["country"], r["isp"], r["response_time"]] for r in results]
41
 
42
  def filter_proxies(proxies, status_filter, protocol_filter, country_filter):
43
  if not proxies:
 
53
 
54
  # Create Gradio interface
55
  with gr.Blocks(title="Proxy Checker") as demo:
56
+ gr.Markdown(f"# Proxy Checker - {datetime(2025, 8, 22, 10, 40).strftime('%I:%M %p, %d/%m/%Y +07')}")
57
 
58
  with gr.Row():
59
  with gr.Column():
 
76
 
77
  # Logic for checking
78
  def update_table(proxy_list):
79
+ try:
80
+ results = check_proxies(proxy_list)
81
+ return gr.Dataframe.update(value=results)
82
+ except Exception as e:
83
+ return gr.Dataframe.update(value=[["Error", "", "", "", "", "", 0]], visible=True)
84
 
85
  check_button.click(
86
  fn=update_table,