#!/bin/bash

function initial {

    if [ -f nmap/initial.nmap ]; then
       echo "[-] initial scan files are already present on system"
       exit 1
    fi

    echo "[-] Initial scan for $1"
    nmap -T4 -oA nmap/initial "$1" 2> /dev/null

}

function allports {

    if [ -f nmap/all-ports.nmap ]; then
        echo "[-] initial scan files are already present on system"
        exit 1
    fi
    echo "[-] Full scna for $1"
    nmap -T4 -p- -sV -oA nmap/all-ports "$1" 2> /dev/null

}

function udp {

    if [ -f nmap/udp.nmap ]; then
        echo "[-] initial scan files are already present on system"
        exit 1
    fi
    echo "[-] UDP scan for $1 (root is needed for that scan-mode)"
    sudo nmap -T4 --top-ports 1000 -sU -oA nmap/udp "$1" 2> /dev/null

}


if [ $# -ne 2 ]; then
    echo '[-] scan <range> <type> (initial, all, udp)'
    exit 1
fi

if [ ! -d nmap/ ]; then
    echo "[*] creating nmap folder"
    mkdir nmap
fi

if [ "$2" = "initial" ]; then
    initial "$1"
elif [ "$2" = "full" ] || [ "$2" = "all" ]; then
    allports "$1"
elif [ "$2" = "udp" ]; then
    udp "$1"
fi