Bash Scripting for Nmap scanning Menu

Introduction
Nmap (Network Mapper) is an open-source tool used for scanning and discovering networks, devices and their open ports. It is one of the first and most commonly used tools for ethical hacking by begineers and is still useful even after you’ve advanced. This bash script is designed to help begineers, like myself run basic scans on one or more IP addresses and saving said scans logs for research later on. This is a CoLab Innovation Hub internship task.
Features
Ports: Display active ports and services, or a details of specific port.
Interactive User interface: Allows users to interact and decide on their scan of choice.
Multiple Scan options: Displays a menu of nmap scans of which the user can use based on what they are testing.
Nmap Installation warning: Warns users when they don’t have nmap installed or updated on their system.
Easy to extend: It is modular and readable making it easier for beginners to add scan types or other tools (nikto, gobuster) later on.
Running the bash script
Prerequisites
A kali or any debian based system
Terminal access
Nmap installed
To install Nmap run:
sudo apt update
sudo apt install nmap
Open the terminal and create a file:
Use nano or any terminal text editor;
nano scan_menu.sh
This is to create an empty file called scan_menu.sh
Paste the script into the file;
#!/bin/bash
if ! command -v nmap &> /dev/null; then
echo "[-] Nmap is not installed. Please install it first."
exit 1
fi
echo "==== Nmap Scan Menu ===="
echo "1. Stealth SYN Scan (-sS -A -T4)"
echo "2. Fast Scan (-F)"
echo "3. Full TCP Scan (all 65535 ports)"
echo "4. Ping Scan (host discovery only)"
echo "5. UDP Scan (-sU -T4)"
echo "6. Exit"
echo "========================"
read -p "Select a scan type [1-6]: " choice
if [ "$choice" -eq 6 ]; then
echo "Goodbye!"
exit 0
fi
read -p "Enter the target IP or domain: " target
case $choice in
1)
echo "[*] Running Stealth SYN Scan on $target..."
nmap -sS -A -T4 "$target" -oN "scan_$target.txt"
;;
2)
echo "[*] Running Fast Scan on $target..."
nmap -F "$target" -oN "scan_$target.txt"
;;
3)
echo "[*] Running Full TCP Scan on $target..."
nmap -p- -T4 "$target" -oN "scan_$target.txt"
;;
4)
echo "[*] Running Ping Scan (host discovery) on $target..."
nmap -sn "$target" -oN "scan_$target.txt"
;;
5)
echo "[*] Running UDP Scan on $target..."
nmap -sU -T4 "$target" -oN "scan_$target.txt"
;;
*)
echo "[-] Invalid choice. Please run the script again."
exit 1
;;
esac
echo "[+] Scan complete. Output saved to scan_$target.txt"
Save and exit;
When done run “CTRL + O” to save and “CTRL + X” to exit the file editor
Make the bash script executable;
Run:
chmod +x scan_menu.sh
Run the script;
./scan_menu.sh
Note: Run it with sudo if root access is required.
Usage
After you run the script, it pops out a menu containing 5 types of scans, numbered 1 - 5 and the 6th option being to exit the menu.
From here a user can pick an option of their choice for the test they wish to run.
Conclusion
Nmap is a powerful tool, used by both advanced and begineer level cyber security personnels, used for scanning and/or discovering networks or devices. This bash script helps by allowing shortening the prompts needed for running the scans and can be modified to add other scans if needed. For further explaination on the script, visit Scan-menu.
Subscribe to my newsletter
Read articles from GREAT OSEH directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by