Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions proxy_tester_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
import time
import requests
import os
import signal

DEFAULT_DOMAIN = "www.google.com"

results = []

def save_results(output_file):
with open(output_file, "w") as file:
for ip, status in results:
file.write(f"{ip}\t{status}\n")

def test_proxy(ip, domain=DEFAULT_DOMAIN):
proxies = {
Expand All @@ -17,11 +24,11 @@ def test_proxy(ip, domain=DEFAULT_DOMAIN):
return True
return False


def test_ip_addresses(ip_file, output_file, domain=DEFAULT_DOMAIN):
with open(ip_file, "r") as file:
ip_addresses = file.read().splitlines()

global results
results = []

for i, ip in enumerate(ip_addresses, start=1):
Expand All @@ -37,34 +44,28 @@ def test_ip_addresses(ip_file, output_file, domain=DEFAULT_DOMAIN):
)
time.sleep(0.1) # Add a slight delay to simulate animation

with open(output_file, "w") as file:
for ip, status in results:
file.write(f"{ip}\t{status}\n")
save_results(output_file)

print("\rTesting complete. ")


def display_menu():
print("Select a file to test:")
print("1. http.txt")
print("2. https.txt")


def get_user_choice():
while True:
choice = input("Enter your choice (1 or 2): ")
if choice in ["1", "2"]:
return choice
print("Invalid choice. Please try again.")


def get_input_filename(choice):
if choice == "1":
return "http.txt"
elif choice == "2":
return "https.txt"


def check_input_files():
http_file = "http.txt"
https_file = "https.txt"
Expand All @@ -76,18 +77,24 @@ def check_input_files():
return False
return True


def get_domain_choice():
domain_choice = input(
"Enter the domain on which you want to test the proxies (default: www.google.com): "
)
return domain_choice.strip() or DEFAULT_DOMAIN

def handle_exit(signal, frame):
print("\nExiting and saving results...")
save_results("results.txt")
exit(0)

def main():
if not check_input_files():
return

signal.signal(signal.SIGINT, handle_exit)
signal.signal(signal.SIGTERM, handle_exit)

display_menu()
choice = get_user_choice()
input_file = get_input_filename(choice)
Expand All @@ -103,6 +110,5 @@ def main():

print("Testing complete. Results saved to", output_file)


if __name__ == "__main__":
main()