2

I installed first the nmap module in PyCharm but received as many others the error for my nmap.PortScanner function.

Therefore, I uninstalled nmap and installed python-nmap.

Now, I have however the problem with executing the command:

import nmap
ns = nmap.PortScanner
ns.scan('My.IP.Add.ress', '1-1024', '-v')
print(ns.scaninfo())

I get for the second line the error message: AttributeError: 'str' object has no attribute '_nmap_path'

However, watching all examples of this, show precisely these lines of code. Can somebody please explain what is happening?

My editor also shows for ns.scaninfo() a warning that the parameter 'self' is not filled. Again, this is not what the examples show. I am very confused by this.

As always, thank you very much for your help!

Alex_P
  • 2,580
  • 3
  • 22
  • 37
  • I'm not sure whether this is the root cause, but you're missing some brackets on the second line. It should be `ns = nmap.PortScanner()`. – Harry Cutts Oct 31 '18 at 22:44

1 Answers1

2

(Since posting my comment I've become convinced that it is the root cause, so posting as an answer.)

You're missing some brackets on the second line. It should read:

ns = nmap.PortScanner()

As it is, you're storing the PortScanner class in ns, as opposed to an object of that class. This means that when you call ns.scan its first parameter (which it's expecting to be self, the PortScanner object with an _nmap_path attribute) is actually a string, which doesn't have the attribute. The same reason is behind your editor's warning about the self parameter not being filled, too.

Harry Cutts
  • 1,352
  • 11
  • 25
  • Thank you very much. This truly did the trick. I must have looked at my code and compared it so many times but the parenthesis, I did not even notice. – Alex_P Nov 01 '18 at 08:49