Created
March 13, 2026 09:29
-
-
Save mrtnvgr/c99cff346ece0344aececd26251f9396 to your computer and use it in GitHub Desktop.
Find Tor proxies in local network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import socket | |
| import concurrent.futures | |
| import argparse | |
| import ipaddress | |
| import subprocess | |
| import re | |
| def get_local_network(): | |
| result = subprocess.run(["ip", "route"], capture_output=True, text=True) | |
| match = re.search(r"(\d+\.\d+\.\d+)\.\d+/\d+", result.stdout) | |
| if match: | |
| return f"{match.group(1)}.0/24" | |
| result = subprocess.run(["hostname", "-I"], capture_output=True, text=True) | |
| if result.stdout: | |
| ip = result.stdout.strip().split()[0] | |
| parts = ip.split(".") | |
| return f"{parts[0]}.{parts[1]}.{parts[2]}.0/24" | |
| return "192.168.1.0/24" | |
| def check_port(ip, port, timeout=2): | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| sock.settimeout(timeout) | |
| try: | |
| sock.connect((str(ip), port)) | |
| sock.close() | |
| return True | |
| except (socket.timeout, socket.error, ConnectionRefusedError): | |
| return False | |
| def check_tor_ports(ip): | |
| results = {} | |
| tor_ports = { | |
| 9050: "SOCKS5", | |
| 9051: "Control", | |
| 8118: "HTTP", | |
| 8123: "HTTP", | |
| } | |
| for port, name in tor_ports.items(): | |
| if check_port(ip, port): | |
| results[port] = name | |
| return results | |
| def scan_network(network, max_workers=100): | |
| net = ipaddress.ip_network(network, strict=False) | |
| print(f"Scanning {network} for Tor proxies...") | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor: | |
| future_to_ip = {executor.submit(check_tor_ports, ip): ip for ip in net.hosts()} | |
| for future in concurrent.futures.as_completed(future_to_ip): | |
| ip = future_to_ip[future] | |
| open_ports = future.result() | |
| if not open_ports: | |
| continue | |
| for port, ptype in open_ports.items(): | |
| print(f"[+] {ip}:{port} ({ptype})") | |
| parser = argparse.ArgumentParser(description="Scan local network for Tor proxies") | |
| parser.add_argument("-n", "--network", default=None, help="Network to scan (e.g., 192.168.1.0/24)") | |
| parser.add_argument("-t", "--threads", type=int, default=100, help="Number of parallel threads") | |
| args = parser.parse_args() | |
| network = args.network or get_local_network() | |
| scan_network(network, args.threads) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment