#!/bin/sh
# quick-scan.sh — a sane first look at one host.
# Usage: ./quick-scan.sh <target>
# Only scan systems you own or have written permission to test.
set -eu
target="${1:?usage: $0 <target>}"
out="scan-$(echo "$target" | tr '/:' '__')-$(date +%Y%m%d-%H%M)"

echo "[*] Fast TCP sweep of all ports on $target"
ports=$(nmap -Pn -p- --min-rate 1000 -T4 "$target" -oG - \
        | awk -F'Ports: ' '/Ports:/{print $2}' \
        | tr ',' '\n' | awk -F/ '$2=="open"{print $1}' | paste -sd, -)

if [ -z "$ports" ]; then
    echo "[-] No open TCP ports found."
    exit 0
fi

echo "[*] Open ports: $ports"
echo "[*] Versions and default scripts, saving to $out.*"
nmap -Pn -sV -sC -p "$ports" "$target" -oA "$out"
