Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
from concurrent.futures import ThreadPoolExecutor
|
| 4 |
import time
|
|
|
|
| 5 |
|
| 6 |
def check_proxy(proxy):
|
| 7 |
proxy_dict = {"http": f"http://{proxy}", "https": f"http://{proxy}"}
|
|
@@ -10,13 +11,13 @@ def check_proxy(proxy):
|
|
| 10 |
|
| 11 |
try:
|
| 12 |
response = requests.get("http://www.google.com", proxies=proxy_dict, timeout=5)
|
| 13 |
-
response_time = (time.time() - start_time) * 1000 #
|
| 14 |
status = "On"
|
| 15 |
except:
|
| 16 |
response_time = 0
|
| 17 |
status = "Off"
|
| 18 |
|
| 19 |
-
#
|
| 20 |
try:
|
| 21 |
ip_info = requests.get(f"http://ip-api.com/json/{address}", timeout=5).json()
|
| 22 |
country = ip_info.get("country", "Unknown")
|
|
@@ -27,56 +28,55 @@ def check_proxy(proxy):
|
|
| 27 |
|
| 28 |
return {"address": address, "port": port, "status": status, "response_time": round(response_time, 2), "protocol": "HTTP", "country": country, "isp": isp}
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def filter_proxies(proxies, status_filter, protocol_filter, country_filter):
|
| 31 |
if not proxies:
|
| 32 |
return []
|
| 33 |
|
| 34 |
filtered = []
|
| 35 |
for proxy in proxies:
|
| 36 |
-
if (status_filter == "All" or proxy[
|
| 37 |
-
(protocol_filter == "All" or proxy[
|
| 38 |
-
(not country_filter or country_filter.lower() in proxy[
|
| 39 |
filtered.append(proxy)
|
| 40 |
return filtered
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
proxies = proxy_list.splitlines()
|
| 47 |
-
results = []
|
| 48 |
-
with ThreadPoolExecutor(max_workers=10) as executor:
|
| 49 |
-
results = list(executor.map(check_proxy, proxies))
|
| 50 |
-
|
| 51 |
-
return results
|
| 52 |
-
|
| 53 |
-
# Tạo giao diện Gradio
|
| 54 |
-
with gr.Blocks(title="Kiểm tra Proxy") as demo:
|
| 55 |
-
gr.Markdown("# Công cụ Kiểm tra Proxy - 11:31 AM, 22/08/2025")
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
with gr.Column():
|
| 59 |
-
proxy_input = gr.Textbox(label="
|
| 60 |
-
check_button = gr.Button("
|
| 61 |
-
stop_button = gr.Button("
|
| 62 |
-
continue_button = gr.Button("
|
| 63 |
|
| 64 |
with gr.Column():
|
| 65 |
with gr.Row():
|
| 66 |
-
status_filter = gr.Radio(["All", "On", "Off"], label="
|
| 67 |
-
protocol_filter = gr.CheckboxGroup(["HTTP", "HTTPS", "SOCKS4", "SOCKS5"], label="
|
| 68 |
-
country_filter = gr.Textbox(label="
|
| 69 |
|
| 70 |
output_table = gr.Dataframe(
|
| 71 |
-
label="
|
| 72 |
-
headers=["
|
| 73 |
interactive=False
|
| 74 |
)
|
| 75 |
|
| 76 |
-
# Logic
|
| 77 |
def update_table(proxy_list):
|
| 78 |
-
|
| 79 |
-
return filter_proxies(results, status_filter.value, protocol_filter.value, country_filter.value)
|
| 80 |
|
| 81 |
check_button.click(
|
| 82 |
fn=update_table,
|
|
@@ -84,9 +84,10 @@ with gr.Blocks(title="Kiểm tra Proxy") as demo:
|
|
| 84 |
outputs=output_table
|
| 85 |
)
|
| 86 |
|
| 87 |
-
#
|
| 88 |
def update_filter(status, protocols, country):
|
| 89 |
-
|
|
|
|
| 90 |
|
| 91 |
status_filter.change(
|
| 92 |
fn=update_filter,
|
|
|
|
| 2 |
import requests
|
| 3 |
from concurrent.futures import ThreadPoolExecutor
|
| 4 |
import time
|
| 5 |
+
from datetime import datetime
|
| 6 |
|
| 7 |
def check_proxy(proxy):
|
| 8 |
proxy_dict = {"http": f"http://{proxy}", "https": f"http://{proxy}"}
|
|
|
|
| 11 |
|
| 12 |
try:
|
| 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")
|
|
|
|
| 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:
|
| 44 |
return []
|
| 45 |
|
| 46 |
filtered = []
|
| 47 |
for proxy in proxies:
|
| 48 |
+
if (status_filter == "All" or proxy[2] == status_filter) and \
|
| 49 |
+
(protocol_filter == "All" or proxy[3] == protocol_filter) and \
|
| 50 |
+
(not country_filter or country_filter.lower() in proxy[4].lower()):
|
| 51 |
filtered.append(proxy)
|
| 52 |
return filtered
|
| 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():
|
| 60 |
+
proxy_input = gr.Textbox(label="Enter proxy list (one per line)", lines=10, placeholder="Example:\n39.104.16.201:80\n87.239.31.42:80")
|
| 61 |
+
check_button = gr.Button("Start Checking")
|
| 62 |
+
stop_button = gr.Button("Stop Checking", interactive=False)
|
| 63 |
+
continue_button = gr.Button("Continue Checking", interactive=False)
|
| 64 |
|
| 65 |
with gr.Column():
|
| 66 |
with gr.Row():
|
| 67 |
+
status_filter = gr.Radio(["All", "On", "Off"], label="Status", value="All")
|
| 68 |
+
protocol_filter = gr.CheckboxGroup(["HTTP", "HTTPS", "SOCKS4", "SOCKS5"], label="Protocol", value=["HTTP"])
|
| 69 |
+
country_filter = gr.Textbox(label="Filter by Country", placeholder="Example: RU, US")
|
| 70 |
|
| 71 |
output_table = gr.Dataframe(
|
| 72 |
+
label="Results",
|
| 73 |
+
headers=["Address", "Port", "Status", "Protocol", "Country", "ISP", "Response Time (ms)"],
|
| 74 |
interactive=False
|
| 75 |
)
|
| 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,
|
|
|
|
| 84 |
outputs=output_table
|
| 85 |
)
|
| 86 |
|
| 87 |
+
# Update filters
|
| 88 |
def update_filter(status, protocols, country):
|
| 89 |
+
current_data = output_table.value or []
|
| 90 |
+
return gr.Dataframe.update(value=filter_proxies(current_data, status, protocols, country))
|
| 91 |
|
| 92 |
status_filter.change(
|
| 93 |
fn=update_filter,
|