Bug Hunter - Program Python Clean IPv6 extraction

Поделиться
HTML-код
  • Опубликовано: 16 янв 2025

Комментарии • 1

  • @sharingilmubarengibnu
    @sharingilmubarengibnu  21 день назад

    from rich.console import Console
    from rich.panel import Panel
    from rich.text import Text
    from rich.table import Table
    from rich import print as rprint
    import re
    import sys
    import os
    console = Console()
    def clear_screen():
    os.system('cls' if os.name == 'nt' else 'clear')
    def show_banner():
    banner = Text()
    banner.append("╔══════════════════════════════════════════╗
    ", style="cyan")
    banner.append("║ IPv6 Extractor Tool v1.0 ║
    ", style="cyan bold")
    banner.append("║ DNS Enumeration & Analysis Tool ║
    ", style="cyan")
    banner.append("╚══════════════════════════════════════════╝
    ", style="cyan")
    console.print(Panel(banner, border_style="cyan"))
    def show_author():
    author = Table(show_header=False, border_style="cyan")
    author.add_row("[cyan]Developer[/cyan]", "[white]:[/white]", "[yellow]Ibnu Rusdianto[/yellow]")
    author.add_row("[cyan]Version[/cyan]", "[white]:[/white]", "[yellow]1.0[/yellow]")
    author.add_row("[cyan]Github[/cyan]", "[white]:[/white]", "[yellow]github.com/ibnurusdianto[/yellow]")
    console.print(Panel(author, title="[cyan]Author Information[/cyan]", border_style="cyan"))
    def show_description():
    desc = """
    This tool is designed to extract IPv6 addresses from DNS enumeration results.
    It processes MassDNS output format and cleanly extracts only the IPv6 addresses.
    Features:
    • Clean IPv6 extraction
    • Duplicate removal
    • Formatted output
    • File handling
    """
    console.print(Panel(desc, title="[cyan]Tool Description[/cyan]", border_style="cyan"))
    def show_usage():
    usage = """
    [cyan]Usage:[/cyan]
    1. Place your input file (output_ipv6.txt) in the same directory
    2. Select option 1 to process the file
    3. Results will be saved to 'extracted_ipv6.txt'
    [cyan]Input Format:[/cyan]
    domain.example.com. AAAA 2606:4700:20::681a:804
    [cyan]Output Format:[/cyan]
    2606:4700:20::681a:804
    """
    console.print(Panel(usage, title="[cyan]Usage Guide[/cyan]", border_style="cyan"))
    def process_file(filename):
    try:
    with open(filename, 'r') as file:
    content = file.read()
    # Extract IPv6 addresses using regex
    ipv6_pattern = r'AAAA\s+([0-9a-fA-F:]+)'
    ipv6_addresses = re.findall(ipv6_pattern, content)
    # Remove duplicates while preserving order
    unique_ipv6 = list(dict.fromkeys(ipv6_addresses))
    # Save to output file
    with open('extracted_ipv6.txt', 'w') as outfile:
    for ip in unique_ipv6:
    outfile.write(f"{ip}
    ")
    # Show results
    result_table = Table(title="Processing Results", border_style="cyan")
    result_table.add_column("Description", style="cyan")
    result_table.add_column("Count", style="green")
    result_table.add_row("Total IPv6 addresses found", str(len(ipv6_addresses)))
    result_table.add_row("Unique IPv6 addresses", str(len(unique_ipv6)))
    result_table.add_row("Output file", "extracted_ipv6.txt")
    console.print(result_table)
    return True
    except FileNotFoundError:
    console.print("[red]Error: Input file not found![/red]")
    return False
    except Exception as e:
    console.print(f"[red]Error: {str(e)}[/red]")
    return False
    def main_menu():
    while True:
    clear_screen()
    show_banner()
    menu = Table(show_header=False, border_style="cyan")
    menu.add_row("[cyan]1.[/cyan]", "[white]Process IPv6 File[/white]")
    menu.add_row("[cyan]2.[/cyan]", "[white]Show Tool Description[/white]")
    menu.add_row("[cyan]3.[/cyan]", "[white]Show Usage Guide[/white]")
    menu.add_row("[cyan]4.[/cyan]", "[white]Show Author Information[/white]")
    menu.add_row("[cyan]5.[/cyan]", "[white]Exit[/white]")
    console.print(Panel(menu, title="[cyan]Main Menu[/cyan]", border_style="cyan"))
    choice = console.input("[cyan]Enter your choice (1-5): [/cyan]")
    if choice == "1":
    clear_screen()
    show_banner()
    console.print("[cyan]Processing file...[/cyan]")
    if process_file('output_ipv6.txt'):
    console.input("
    [green]Press Enter to continue...[/green]")
    elif choice == "2":
    clear_screen()
    show_banner()
    show_description()
    console.input("
    [cyan]Press Enter to continue...[/cyan]")
    elif choice == "3":
    clear_screen()
    show_banner()
    show_usage()
    console.input("
    [cyan]Press Enter to continue...[/cyan]")
    elif choice == "4":
    clear_screen()
    show_banner()
    show_author()
    console.input("
    [cyan]Press Enter to continue...[/cyan]")
    elif choice == "5":
    clear_screen()
    console.print("[cyan]Thank you for using IPv6 Extractor Tool![/cyan]")
    sys.exit(0)
    else:
    console.print("[red]Invalid choice! Please try again.[/red]")
    console.input("
    Press Enter to continue...")
    if __name__ == "__main__":
    main_menu()