Skip to content
avitwilPublic

About

Python Nmap wrapper with colorful output, JSON export, and hardened target parsing

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

Snmap

License: MIT Python 3

Python 3 wrapper around Nmap. It checks targets before the scan, runs Nmap, and prints port state, service details, and script output in color. Results can also be saved as JSON.

Author: Avi Twil

Contents

Authorized use only

Scan only systems you own or have explicit permission to test. Unauthorized network scanning may be illegal. You are responsible for how you use this tool.

The screenshots below are from a local lab: a web server on 127.0.0.1 only. Other addresses in this README are documentation examples from RFC 5737 (203.0.113.0/24).

Features

  • Scan one host, a file of hosts, or a CIDR subnet
  • Pass any Nmap flags through (-sS is the default)
  • Color for open, filtered, and closed ports, plus service and OS details
  • JSON export of the same result
  • Reject targets that look like extra command-line flags

How it works

  1. You choose targets with -t, -f, or -ts.
  2. Snmap accepts only values that look like a host, hostname, or CIDR range. A value that starts with - is skipped, so it cannot be smuggled in as another Nmap option.
  3. The script calls Nmap through python-nmap.
  4. It prints each host in the terminal, or writes the same structure to a file when you pass --json.

-flags must be the last option on the command line. Everything after it is handed to Nmap, including -t, -f, -ts, and --json.

Install

You need Python 3 and Nmap on PATH. Some scan types (-sS, -sU, -O) need root.

git clone https://github.com/avitwil/Snmap.git
cd Snmap
python3 -m pip install -r requirements.txt

On Debian, Ubuntu, or Kali, ./dist/install.sh installs the nmap package and the Python dependencies.

The file you run is super_nmap.py.

Older v1 packages are on GitHub Releases, not in the git tree. They predate the current target checks. Prefer the source install above.

Usage

python3 super_nmap.py --help

Snmap help menu, including the authorized-use line and target options

The help text prints a private-range placeholder (192.168.1.0/24). That line is not a host this project scanned.

Option Meaning
-t, --target One host
-f, --file Text file, one target per line
-ts, --subnet CIDR subnet
-flags, --flags Nmap flags. Must be last
--json <file> Write results as JSON instead of printing them
-h, --help Show the help menu

Common Nmap flags to put after -flags: -sT, -sS, -sV, -O, -p, -F, --open, --script. The help menu lists the rest.

Examples

Local scan

TCP connect scan of port 8080 on this machine, with service detection. Connect scan (-sT) does not need root.

python3 super_nmap.py -t 127.0.0.1 -flags -sT -sV -p 8080 --open

Local scan of 127.0.0.1 showing port 8080 open

Expected result for that local web server:

Host: 127.0.0.1
  [ Ports ]
    Port 8080/tcp: open | http SimpleHTTPServer 0.6 | Reason: syn-ack

JSON export

Put --json before -flags.

python3 super_nmap.py -t 127.0.0.1 --json results.json -flags -sT -sV -p 8080

The terminal ends with Results saved to results.json. The file from the local scan above looks like this:

{
  "127.0.0.1": {
    "ports": [
      {
        "protocol": "tcp",
        "port": 8080,
        "state": "open",
        "service": "http",
        "product": "SimpleHTTPServer",
        "version": "0.6",
        "reason": "syn-ack"
      }
    ]
  }
}

File of hosts

printf '%s\n' 127.0.0.1 > hosts.txt
python3 super_nmap.py -f hosts.txt -flags -sT -p 8080

Lines that are not valid targets are skipped with a warning. The rest are scanned.

Documentation addresses

203.0.113.0/24 is TEST-NET-3, reserved for examples. These commands are illustrations, not scans run for this README.

python3 super_nmap.py -t 203.0.113.10 -flags -sV
python3 super_nmap.py -ts 203.0.113.0/24 -flags -sT --open

Flags must be last

This is correct. The target is parsed, then -sV is passed to Nmap:

python3 super_nmap.py -t 203.0.113.10 -flags -sV

This is wrong. -t and the address are swallowed as Nmap flags, and Snmap reports that no target was set:

python3 super_nmap.py -flags -sV -t 203.0.113.10

Troubleshooting

  • File not found: the -f path does not exist.
  • No valid targets: nothing passed the target check, or the target options were placed after -flags.
  • nmap program was not found in path: install Nmap and open a new shell.
  • SYN, UDP, or OS scans fail: run them with root, or use -sT for a connect scan.

License

MIT. See LICENSE.

About

Python Nmap wrapper with colorful output, JSON export, and hardened target parsing

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages