0

I am currently learning ethical hacking with python and am trying to use Nmap however after installing it, and doing some simple scripting I get the following error:

Traceback (most recent call last):
  File "nmap_test.py", line 3, in <module>
    nmap1 = nmap.PortScanner()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nmap/nmap.py", line 131, in __init__
    os.getenv('PATH')
nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'

Previous to this I got a different error saying the following:

Traceback (most recent call last):
  File "nmap_test.py", line 3, in <module>
    nmap1 = nmap.PortScanner()
AttributeError: module 'nmap' has no attribute 'PortScanner'

With the bottom error I had installed just 'nmap' using pip3 (as I am using python3.7) and when that did not work I uninstalled 'nmap' and installed 'python-nmap' but then I got the top error message.

Please can someone help me out, I would greatly appreciate it. I have included my code below just for reference.

import nmap

nmap1 = nmap.PortScanner()

a = nmap1.nmap_version()

print(a)
D.Denton
  • 71
  • 1
  • 7
  • 2
    python-nmap is definitely the package you want. The other nmap is a numerical package that doesn't appear to be maintained. The problem you're running into in that the nmap python module requires the nmap binary to be installed on your system and to be in a known location or on the path. In this case, it's not finding the nmap binary on the path. It looks like you're on macOS. The easiest way to get the nmap binary is to install it via homebrew: `brew install nmap` (if you have homebrew set up) – John Szakmeister Jan 02 '19 at 15:17
  • This first answer in the following might help you: https://stackoverflow.com/questions/15335753/nmap-not-found-class-nmap-nmap-portscannererror – Nordle Jan 02 '19 at 15:18
  • @JohnSzakmeister do you have a link to how to set up homebrew please, thanks for the help so far – D.Denton Jan 02 '19 at 15:21
  • Check out the Homebrew website: https://brew.sh/ It has all the details you need. :-) – John Szakmeister Jan 02 '19 at 15:21
  • I have now installed nmap with brew but I still get Traceback (most recent call last): File "nmap_test.py", line 3, in nmap1 = nmap.PortScanner() AttributeError: module 'nmap' has no attribute 'PortScanner' – D.Denton Jan 02 '19 at 15:31
  • never mind it works now thanks a lot!! – D.Denton Jan 02 '19 at 15:33
  • You're welcome! Glad you got it working. – John Szakmeister Jan 04 '19 at 00:18
  • All possible issues with `nmap` have been described [here](https://stackoverflow.com/questions/71652574/getting-error-attributeerror-module-nmap-has-no-attribute-portscanner/71660197) in details. Thx – gremur Mar 30 '22 at 11:12

3 Answers3

1

Nmap is a tool used for Networking Scanning. First install nmap dependencies using the command

pip install python-nmap

If you want to use the nmap tool directly in debian.

sudo apt install nmap

This will work for you more efficiently.

Akash M
  • 31
  • 4
0

The top error message,

nmap program was not found

is because the nmap application does not exist, even though the nmap.py module exists. To fix it you have to install the nmap application:

$ brew install nmap

Alexandre Tranchant
  • 4,426
  • 4
  • 43
  • 70
0

There are two types of nmpas

uninstall nmap

pip uninstall nmap

then install

pip install python-nmap

still use import nmap though

cube8868
  • 1
  • 1