Python3-nmap converts Nmap commands into python3 methods making it very easy to use nmap in any of your python pentesting projects. It provides a Python 3 interface to the Nmap port scanner, enabling manipulation of scan results and automation of scanning tasks and reports. The library is actively maintained, with the latest stable release being 1.9.1.
pip install python3-nmapVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes the `nmap3.Nmap` class and performs a top ports scan on a specified target. It then prints the host and open port information. Remember to have the Nmap binary installed on your system.
Install the Nmap binary appropriate for your operating system. Ensure its executable path is included in your system's PATH environment variable.
If you installed `python3-nmap`, use `from nmap3 import Nmap`. If you intend to use the older API, install `python-nmap` instead (`pip install python-nmap`).
Execute your Python script with `sudo python your_script.py` on Linux/macOS or run your terminal/IDE as an administrator on Windows when performing privileged scans.
Refer to the `python3-nmap` documentation for its current API if migrating from `python-nmap`. If using older `python-nmap`, check its changelog for specific breaking changes.
Install the Nmap command-line tool for your operating system (e.g., `sudo apt install nmap` on Debian/Ubuntu, `brew install nmap` on macOS, or download from nmap.org for Windows). Ensure the Nmap executable's directory is in your system's PATH.
Verify that the Nmap binary is installed and its location is in your system's PATH. For Windows users, you might need to manually add the Nmap installation directory to your environment variables.
Change your import statement from `import nmap` to `from nmap3 import Nmap` and adapt your code to use the `nmap3` API. If you specifically need the `PortScanner` class, you might need to uninstall `python3-nmap` and install `python-nmap` instead (`pip install python-nmap`).
Ensure `python3-nmap` is installed in your active Python environment: `pip install python3-nmap`. If using a virtual environment, activate it before installing. Verify with `pip show python3-nmap`.