# https://t.me/Exploit_0x

import os
import socket
import subprocess
import sys
import whois
import time
import dns.resolver
from datetime import datetime
from colorama import Fore, Style, init

# Initialize colorama
init(autoreset=True)

# Color shortcuts
R = Fore.RED
G = Fore.GREEN
Y = Fore.YELLOW
C = Fore.CYAN
M = Fore.MAGENTA
B = Fore.BLUE
W = Fore.WHITE

# Common subdomains and ports
subdomains = ["mail", "ftp", "cpanel", "webmail", "ns1", "ns2", "dev", "test", "server", "api", "db", "ssh", "smtp", "vpn", "blog", "direct"]
common_ports = [21, 22, 23, 25, 53, 80, 110, 143, 443, 465, 587, 993, 995, 3306, 8080, 8443]

def box_print(title, content_lines):
    width = max(len(title), max((len(line) for line in content_lines), default=0)) + 4
    print(M + "╔" + "═" * width + "╗")
    print(M + f"║ {title.center(width - 2)} ║")
    print(M + "╠" + "═" * width + "╣")
    for line in content_lines:
        print(M + f"║ {line.ljust(width - 2)} ║")
    print(M + "╚" + "═" * width + "╝")

def disclaimer():
    box_print("DISCLAIMER", [
        "This tool is for EDUCATIONAL PURPOSES ONLY.",
        "Only scan domains you own or are authorized to test."
    ])
    agree = input(G + "Do you agree? (y/n): ").lower()
    if agree != "y":
        print(R + "[-] Exiting. Stay ethical.")
        sys.exit()

def resolve_domain(domain):
    try:
        ip = socket.gethostbyname(domain)
        return ip
    except socket.gaierror:
        return None

def whois_lookup(domain):
    result = []
    try:
        info = whois.whois(domain)
        result.append(f"Registrar: {info.registrar}")
        result.append(f"Created: {info.creation_date}")
        result.append(f"Expires: {info.expiration_date}")
        result.append(f"Name Servers: {', '.join(info.name_servers or [])}")
        result.append(f"Emails: {info.emails}")
    except Exception as e:
        result.append(f"WHOIS failed: {e}")
    return result

def scan_dns(domain):
    records = []
    types = ['A', 'MX', 'NS', 'TXT', 'CNAME']
    for record_type in types:
        try:
            answers = dns.resolver.resolve(domain, record_type, raise_on_no_answer=False)
            for rdata in answers:
                records.append(f"[{record_type}] {rdata}")
        except:
            continue
    return records

def scan_subdomains(domain):
    found = []
    for sub in subdomains:
        full = f"{sub}.{domain}"
        try:
            ip = socket.gethostbyname(full)
            found.append(f"{full} => {ip}")
        except:
            continue
    return found

def port_scan(ip):
    open_ports = []
    for port in common_ports:
        try:
            s = socket.socket()
            s.settimeout(0.5)
            s.connect((ip, port))
            try:
                banner = s.recv(100).decode().strip()
            except:
                banner = "No Banner"
            open_ports.append(f"{port}/tcp open - {banner}")
            s.close()
        except:
            continue
    return open_ports

def ping_check(domain):
    try:
        response = subprocess.getoutput(f"ping -c 1 {domain}")
        return response.split("\n")[0]
    except:
        return "Ping failed"

def banner():
    box_print("Ultimate Origin IP Scanner", [
        "Version: 1.0",
        "Author: DarkFolder [Admin]",
        "Compatible: Termux, Linux"
    ])

def main():
    os.system("clear")
    banner()
    disclaimer()
    domain = input(Y + "Enter target domain (example.com): ").strip()
    start_time = datetime.now()

    ip = resolve_domain(domain)
    if not ip:
        print(R + "[-] Domain resolution failed.")
        return

    # Run scans
    ping_res = ping_check(domain)
    whois_data = whois_lookup(domain)
    dns_records = scan_dns(domain)
    subdomain_hits = scan_subdomains(domain)
    port_results = port_scan(ip)

    # Output in boxes
    box_print("Resolved Domain", [f"{domain} => {ip}"])
    box_print("Ping Check", [ping_res])
    box_print("WHOIS Info", whois_data)
    box_print("DNS Records", dns_records)
    box_print("Discovered Subdomains", subdomain_hits if subdomain_hits else ["None found"])
    box_print("Open Ports & Banners", port_results if port_results else ["No open ports found"])

    duration = (datetime.now() - start_time).total_seconds()
    print(B + f"\n[✓] Scan completed in {duration:.2f} seconds.")
    print(W + "[!] Use this knowledge responsibly.")

if __name__ == "__main__":
    main()
