diff --git a/README.md b/README.md index 173a683..2b8330d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,92 @@ + + +## Proxy Tester + +The Proxy Tester script is designed to test the validity and response time of HTTP/HTTPS proxies. It uses the `faster_than_requests` library for faster proxy testing. + +### Prerequisites + +Make sure you have Python 3 installed on your system. You can download Python from the official website: [Python Downloads](https://www.python.org/downloads/) + +### Installation + +1. Clone the repository or download the script files to your local machine. +2. Open a terminal or command prompt and navigate to the directory where the script files are located. +3. Create a virtual environment (optional but recommended): + - Run `python3 -m venv env` to create a virtual environment named "env". + - Activate the virtual environment: + - On Windows: `.\env\Scripts\activate` + - On macOS/Linux: `source env/bin/activate` +4. Install the required dependencies by running the following command: + ``` + pip install -r requirements.txt + ``` + +### Usage + +1. Prepare a text file containing a list of HTTP proxies. Each proxy should be in the format `host:port`, with each proxy on a new line. Save the file as `http.txt`. +2. Prepare a text file containing a list of HTTPS proxies. Each proxy should be in the format `host:port`, with each proxy on a new line. Save the file as `https.txt`. +3. Run the script using the following command: + ``` + python proxy_tester_menu.py http.txt https.txt output.txt + ``` + Replace `http.txt` and `https.txt` with the actual file names of your proxy lists. The results will be saved to `output.txt`. +4. The script will start testing the proxies and display the progress and results in the terminal. +5. Once the testing is complete, the results will be saved to the specified output file (`output.txt`). +6. You can open the output file to view the results. Each line will contain the proxy address, response time, and validity status. + +Note: If you encounter any errors or issues, please ensure that the proxy files (`http.txt` and `https.txt`) are correctly formatted, and the proxy servers are accessible. + + + +## Features + +- Validates proxies by sending HTTP requests to specified domains. +- Supports both HTTP and HTTPS proxies. +- Multi-threaded for faster testing. +- Configurable number of threads. +- Customizable timeout for request. +- Generates a report with the results. + +## Requirements + +- Python 3.6+ +- Packages listed in the `requirements.txt` file. + +## Usage + +1. Clone the repository: + + ```shell + git clone https://github.com/your-username/proxy-tester.git + ``` + +2. Install the required packages: + + ```shell + pip install -r requirements.txt + ``` + +3. Prepare your proxy list in the `input.txt` file, with each proxy URL on a new line. + +4. Run the script: + + ```shell + python proxy_tester_menu.py input.txt output.txt + ``` + + - `input.txt` is the path to your input file containing the list of proxies. + - `output.txt` is the path to the output file where the test results will be saved. + +## Configuration + +You can modify the following settings in the `proxy_tester_menu.py` script: + +- `THREADS`: The number of threads to use for testing proxies. +- `TIMEOUT`: The timeout for each request. + + + # SOCKER Checks for valid SOCKS4 & SOCKS5 proxies. diff --git a/proxy_tester_menu.py b/proxy_tester_menu.py index f7771c7..286cf80 100644 --- a/proxy_tester_menu.py +++ b/proxy_tester_menu.py @@ -1,41 +1,59 @@ import contextlib import time -import requests import os +import argparse +import concurrent.futures +import subprocess DEFAULT_DOMAIN = "www.google.com" def test_proxy(ip, domain=DEFAULT_DOMAIN): - proxies = { - "http": f"http://{ip}", - "https": f"http://{ip}", - } - with contextlib.suppress(requests.RequestException): - response = requests.get(f"http://{domain}", proxies=proxies, timeout=5) - if response.status_code >= 200 and response.status_code < 300: - return True - return False - - -def test_ip_addresses(ip_file, output_file, domain=DEFAULT_DOMAIN): + url = f"http://{domain}" + proxy_url = f"http://{ip}" + proxies = {'http': proxy_url, 'https': proxy_url} + + try: + # Use subprocess to make requests using cURL + command = f"curl --connect-timeout 5 --max-time 5 --proxy {proxy_url} {url}" + result = subprocess.run( + command, + shell=True, + capture_output=True, + text=True, + ) + + # Check if the request was successful + return result.returncode == 0 + except subprocess.SubprocessError: + return False + + +def test_ip_addresses(ip_file, output_file, domain=DEFAULT_DOMAIN, num_threads=10): with open(ip_file, "r") as file: ip_addresses = file.read().splitlines() results = [] - for i, ip in enumerate(ip_addresses, start=1): - is_working = test_proxy(ip, domain=domain) - status = "Active" if is_working else "Inactive" - results.append((ip, status)) - - progress = i / len(ip_addresses) * 100 - print( - f'\rTesting - Progress: {progress:.1f}% | {"." * (i % 4)} ', - end="", - flush=True, - ) - time.sleep(0.1) # Add a slight delay to simulate animation + with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor: + futures = [] + for ip in ip_addresses: + future = executor.submit(test_proxy, ip, domain) + futures.append(future) + + for i, future in enumerate(concurrent.futures.as_completed(futures), start=1): + ip = ip_addresses[i - 1] + is_working = future.result() + status = "Active" if is_working else "Inactive" + results.append((ip, status)) + + progress = i / len(ip_addresses) * 100 + print( + f'\rTesting - Progress: {progress:.1f}% | {"." * (i % 4)} ', + end="", + flush=True, + ) + time.sleep(0.1) # Add a slight delay to simulate animation with open(output_file, "w") as file: for ip, status in results: @@ -84,6 +102,11 @@ def get_domain_choice(): return domain_choice.strip() or DEFAULT_DOMAIN +def get_num_threads(): + num_threads = input("Enter the number of threads to use for testing (default: 10): ") + return int(num_threads.strip() or "10") + + def main(): if not check_input_files(): return @@ -91,17 +114,11 @@ def main(): display_menu() choice = get_user_choice() input_file = get_input_filename(choice) - output_file = "results.txt" - - print("Testing in progress...") - time.sleep(1) # Simulate a delay before starting the testing - + output_file = "output.txt" domain = get_domain_choice() - print(f"Using domain: {domain}") - - test_ip_addresses(input_file, output_file, domain=domain) + num_threads = get_num_threads() - print("Testing complete. Results saved to", output_file) + test_ip_addresses(input_file, output_file, domain, num_threads) if __name__ == "__main__": diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cbbef67 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +certifi==2021.5.30 +chardet==4.0.0 +idna==2.10 +requests==2.26.0 +urllib3==1.26.7