Simple python script that automates Nmap scans: quick port discovery + detailed analysis on open ports.
Goal of this script is to automatize the nmap commands I always use.
nmaper is a simple Python script to automate Nmap scans in two steps:
- Quick scan to detect open ports
nmap <IP> -Pn --open- In-depth scan with service, version, and OS detection only on the open ports found:
nmap <IP> -Pn -p PORT1,PORT2,... -A -oN nmap_<IP>.txtnmaper.py IP/FILE [OPTIONS]
OPTIONS:
ALL : Scan all ports (-p-)
(all other valid Nmap options are also accepted directly)
- Scan a single target with the default quick and in-depth scan
nmaper.py 192.168.1.1- Scan all ports of a target (
-p-)
nmaper.py 192.168.1.1 ALL- Use nmaper with custom options (fast UDP scan)
nmaper.py 192.168.1.1 -sU -T4- Scan multiple targets listed in a file:
nmaper.py targets.txtTo make nmaper accessible globally in your terminal, follow these steps:
- Copy
nmaper.pyto/optand make it executable:
sudo cp nmaper.py /opt/
sudo chmod +x /opt/nmaper.py- Create a small wrapper script in
/usr/local/bin/nmaper:
#!/bin/bash
/opt/nmaper.py "$@"- Make the wrapper executable:
sudo chmod +x /usr/local/bin/nmaper- Accepts a single IP or a file with multiple targets
- Smart two-step scan:
- 1st pass: detect open ports (
--open) - 2nd pass: in-depth scan with detection (
-A) only on detected ports
- 1st pass: detect open ports (
- Only the
ALLoption is handled internally - All other valid Nmap options can be passed directly
- Color-coded output for readability
- Automatically saves results to
.txtfiles
This script is an improved version inspired by OlivierProTips/nmaper: