Where is the problem?
import nmap
I installed nmap and python, and when I use import nmap
there is no any problem. But when use:
nmap.PortScanner()
this error is thrown:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
nmap.PortScanner()
File "./nmap/nmap.py", line 153, in __init__
raise PortScannerError('nmap program was not found in path. PATH is:{0}'.format(os.getenv('PATH')))
nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : /usr/lib /lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/games'"
Under windows, you must first install nmap for windows, you can install with this link https://nmap.org/download.html
Faced similar issue while trying to run
nm= nmap.PortScanner()
I tried most of the solutions given above, but they did not work for me. The thing that worked for me was installing nmap for Mac OS X using home brew (Information at: http://brew.sh) and running the command
Now
nm= nmap.PortScanner()
runs without the earlier error.Running on Raspberry Pi 3 with Jessy lite
I had to:
then I could:
python-nmap
seems to depend onnmap
, which is the binary that does the actual network scanning and auditing.You can check in a terminal if nmap is in your
$PATH
with the following command:Debian-like
You can install nmap in debian-like distros with:
Arch linux:
Already installed
nmap
If you're sure the
nmap
binary is installed, but you think it is not in your$PATH
, you might have to add the directory where nmap is installed to your$PATH
.To do that, edit the
.bashrc
file in your user's directory, or/etc/bashrc
(which will change for all users) and add the following:but changing
/usr/local/nmap/bin
for the directory where the nmap binary is installed. After changing the file, be sure to open a new shell session, or typeexec bash
to refresh it.You also have to make sure, that it has execute permission (
chmod +x <file>
).When you execute:
You should see something like this:
If you do,
nmap
is installed and in your$PATH
.For Windows users:
I would suggest first closing all terminals and IDLE or any other window you currently have opened when trying to run your script.
Next, open a command line and type
If you are unsure if Nmap binaries are installed on your current system, do a simple search for
from your start menu. If it is installed, continue to the next step, if not, go to Nmap's official download page
Download the windows self install and run it. Record the directory it is being installed to.
Go to that directory. For me it was
C:\Program Files (x86)\Nmap
Open your system's environment variables editor usually found in
Or right click
select
Path
for bothYou
and theSystem
press
Edit
and enter thefull path to your Nmap director
eg
;C:\Program Files (x86)\Nmap\
Press ok and exit the editor.
Now go back to your command line and enter:
pip install python-nmap
Allow it to install and then restart youride
and test your code again.Note about nmap
I used nmap to search the mask 192.168.1.0/24, but it didnt seam to find ALL ip´s. Eg: my laptop on 192.168.1.119 wasnt found, so I ended up using a combination of:
inside a multithreaded Pinger
Pinger I got from: http://blog.boa.nu/2012/10/python-threading-example-creating-pingerpy.html
I created my own IpInfo class to store information and search for open ports on each IP, and here I use nmap: (Code is "work in progress", but you will get the idea. Ideas to tune performance would be nice)