import gradio as gr import requests from concurrent.futures import ThreadPoolExecutor import time from datetime import datetime def check_proxy(proxy): proxy_dict = {"http": f"http://{proxy}", "https": f"http://{proxy}"} address, port = proxy.split(':') start_time = time.time() try: response = requests.get("http://www.google.com", proxies=proxy_dict, timeout=5) response_time = (time.time() - start_time) * 1000 # Convert to ms status = "On" except Exception as e: response_time = 0 status = "Off" # Call ip-api.com for country and ISP with error handling try: ip_info = requests.get(f"http://ip-api.com/json/{address}", timeout=5).json() country = ip_info.get("country", "Unknown") isp = ip_info.get("isp", "Unknown") except Exception as e: country = "Unknown" isp = "Unknown" return {"address": address, "port": port, "status": status, "response_time": round(response_time, 2), "protocol": "HTTP", "country": country, "isp": isp} def check_proxies(proxy_list): if not proxy_list: return [["No proxies provided", "", "", "", "", "", 0]] proxies = proxy_list.splitlines() results = [] with ThreadPoolExecutor(max_workers=5) as executor: # Increased workers for better performance results = list(executor.map(check_proxy, proxies)) return [[r["address"], r["port"], r["status"], r["protocol"], r["country"], r["isp"], r["response_time"]] for r in results] def filter_proxies(proxies, status_filter, protocol_filter, country_filter): if not proxies: return [] filtered = [] for proxy in proxies: if (status_filter == "All" or proxy[2] == status_filter) and \ (protocol_filter == "All" or proxy[3] == protocol_filter) and \ (not country_filter or country_filter.lower() in proxy[4].lower()): filtered.append(proxy) return filtered # Create Gradio interface with gr.Blocks(title="Proxy Checker") as demo: gr.Markdown(f"# Proxy Checker - {datetime(2025, 8, 22, 10, 40).strftime('%I:%M %p, %d/%m/%Y +07')}") with gr.Row(): with gr.Column(): 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") check_button = gr.Button("Start Checking") stop_button = gr.Button("Stop Checking", interactive=False) continue_button = gr.Button("Continue Checking", interactive=False) with gr.Column(): with gr.Row(): status_filter = gr.Radio(["All", "On", "Off"], label="Status", value="All") protocol_filter = gr.CheckboxGroup(["HTTP", "HTTPS", "SOCKS4", "SOCKS5"], label="Protocol", value=["HTTP"]) country_filter = gr.Textbox(label="Filter by Country", placeholder="Example: RU, US") output_table = gr.Dataframe( label="Results", headers=["Address", "Port", "Status", "Protocol", "Country", "ISP", "Response Time (ms)"], interactive=False ) # Logic for checking def update_table(proxy_list): try: results = check_proxies(proxy_list) return gr.Dataframe.update(value=results) except Exception as e: return gr.Dataframe.update(value=[["Error", "", "", "", "", "", 0]], visible=True) check_button.click( fn=update_table, inputs=proxy_input, outputs=output_table ) # Update filters def update_filter(status, protocols, country): current_data = output_table.value or [] return gr.Dataframe.update(value=filter_proxies(current_data, status, protocols, country)) status_filter.change( fn=update_filter, inputs=[status_filter, protocol_filter, country_filter], outputs=output_table ) protocol_filter.change( fn=update_filter, inputs=[status_filter, protocol_filter, country_filter], outputs=output_table ) country_filter.change( fn=update_filter, inputs=[status_filter, protocol_filter, country_filter], outputs=output_table ) demo.launch()