#!/bin/bash

# Function to check for open ports
check_ports() {
    target_ip=$1
    echo "Checking for open ports on $target_ip..."

    # Use Rustscan to scan for open ports
    open_ports=$(rustscan -a $target_ip -r 1-65535 -u 5000 2>/dev/null | grep "Open")

    # Check if any open ports were found
    if [ -n "$open_ports" ]; then
        echo "Open ports found:"
        echo "$open_ports"

        # Extract and process open ports
        echo "$open_ports" | while read -r line; do
            port=$(echo "$line" | awk '{print $4}')
            echo "Processing port: $port"

            # Identify the next command based on the port
            case $port in
                22)
                    echo "Next command: ssh <username>@$target_ip"
                    ;;
                80)
                    echo "Next command: wget http://$target_ip"
                    ;;
                443)
                    echo "Next command: curl https://$target_ip"
                    ;;
                8080)
                    echo "Next command: nmap -sC -sV $target_ip"
                    ;;
                21)
                    echo "Next command: ftp $target_ip"
                    ;;
                25)
                    echo "Next command: telnet $target_ip 25"
                    ;;
                110)
                    echo "Next command: telnet $target_ip 110"
                    ;;
                143)
                    echo "Next command: telnet $target_ip 143"
                    ;;
                3306)
                    echo "Next command: mysql -h $target_ip -u <username> -p"
                    ;;
                3389)
                    echo "Next command: rdesktop $target_ip"
                    ;;
                5900)
                    echo "Next command: vncviewer $target_ip"
                    ;;
                8081)
                    echo "Next command: nmap -sC -sV $target_ip -p 8081"
                    ;;
                8888)
                    echo "Next command: curl http://$target_ip:8888"
                    ;;
                9200)
                    echo "Next command: curl -X GET http://$target_ip:9200"
                    ;;
                *)
                    echo "Port $port is open. Please manually investigate."
                    ;;
            esac
        done
    else
        echo "No open ports found or target IP might be incorrect."
    fi
}

# Check if target IP is provided
if [ -z "$1" ]; then
    echo "Usage: $0 <target_ip>"
    exit 1
fi

# Call the function to check for open ports
check_ports $1
