Reputation: 21
Recently I have been learning python and I have just started a project making a nmap scanning script that will scan a network range for open ports. My only problem is that I have installed the nmap module but in my code, it says that the module does not have the attribute port scanner when I attempt to run it. I have looked around quite a bit for a solution and I have seen a lot of different solutions I will list what I have tried here. First was to install python-nmap that didn't work Next was to install the module nmap this didn't work either I also heard you should uninstall nmap and install python-nmap instead this also did not work Next It was suggested that since I am using python3 I should use pip3 to install python-nmap that didn't work either Next I tried manually downloading and installing it and putting it in /lib/python3.7/dist-packages this didn't seem to do anything
I did notice that even though the installation did not fail on any of these methods only the manual install made it show up in the dist-packages folder and it still did not work after this. None of my versions of python have the nmap module inside of them. Does anyone know anything else that I should try to make this work? I am currently running a Debian 9 based os. thanks for your help in advance. this is the error
Cannot find reference 'PortScanner' in '__Init__.py'
this is my code
import nmap
ns = nmap.PortScanner()
Upvotes: 0
Views: 8321
Reputation: 23498
Basically you have to install nmap
:
sudo apt-get install nmap
Then install python module:
sudo pip3 install -U python-nmap
After this you're good to go:
>>> import nmap
>>> nm = nmap.PortScanner()
>>> nm.scan('127.0.0.1', '22-443')
>>> nm.command_line()
'nmap -oX - -p 22-443 -sV 127.0.0.1'
>>> nm.scaninfo()
{'tcp': {'services': '22-443', 'method': 'connect'}}
>>> nm.all_hosts()
['127.0.0.1']
>>> nm['127.0.0.1'].hostname()
'localhost'
>>> nm['127.0.0.1'].state()
'up'
>>> nm['127.0.0.1'].all_protocols()
['tcp']
>>> nm['127.0.0.1']['tcp'].keys()
[80, 25, 443, 22, 111]
Upvotes: 1