import random
import socket
import threading
from concurrent.futures import ThreadPoolExecutor

# Generate random IPs (excluding private/ranges)
def generate_random_ip():
    # Avoid private IPs and banned country ranges (simplified)
    first = random.randint(1, 223)
    while first in [10, 127, 172, 192, 169]:  # Skip private ranges
        first = random.randint(1, 223)
    
    return f"{first}.{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}"

def check_port(ip, port):
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(2)
        result = sock.connect_ex((ip, port))
        sock.close()
        return result == 0
    except:
        return False

# Check common vulnerable ports
VULN_PORTS = [21, 22, 23, 80, 443, 445, 3389, 5900, 5985, 8080, 8443]

print("[*] Scanning random IPs for open vulnerable ports...")
vulnerable_ips = []

def scan_ip(ip):
    open_ports = []
    for port in VULN_PORTS:
        if check_port(ip, port):
            open_ports.append(port)
    if open_ports:
        vulnerable_ips.append((ip, open_ports))
        print(f"[!] Found: {ip} - Ports: {open_ports}")

# Scan 1000 random IPs
with ThreadPoolExecutor(max_workers=50) as executor:
    for _ in range(1000):
        ip = generate_random_ip()
        executor.submit(scan_ip, ip)

print(f"\n[+] Found {len(vulnerable_ips)} potentially vulnerable hosts")
with open('vulnerable_targets.txt', 'w') as f:
    for ip, ports in vulnerable_ips[:50]:  # Take top 50
        f.write(f"{ip}:{','.join(map(str, ports))}\n")
        print(f"  {ip} - {ports}")

