I have tried these methods but not worked then I further looked into it.
Error:
>>> import nmap
>>> nm = nmap.PortScanner()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nmap/nmap.py", line 137, in __init__
raise PortScannerError('nmap program was not found in path')
nmap.nmap.PortScannerError: 'nmap program was not found in path'
so I looked into file "/usr/local/lib/python2.7/dist-packages/nmap/nmap.py". The code where they are checking for nmap is not working for some reason.
code:
# regex used to detect nmap
regex = re.compile('Nmap version [0-9]*\.[0-9]*[^ ]* \( http://nmap\.org \)')
# launch 'nmap -V', we wait after 'Nmap version 5.0 ( http://nmap.org )'
p = subprocess.Popen(['nmap', '-V'], bufsize=10000, stdout=subprocess.PIPE)
self._nmap_last_output = p.communicate()[0] # store stdout
for line in self._nmap_last_output.split('\n'):
if regex.match(line) is not None:
is_nmap_found = True
# Search for version number
regex_version = re.compile('[0-9]+')
regex_subversion = re.compile('\.[0-9]+')
rv = regex_version.search(line)
rsv = regex_subversion.search(line)
if rv is not None and rsv is not None:
# extract version/subversion
self._nmap_version_number = int(line[rv.start():rv.end()])
self._nmap_subversion_number = int(line[rsv.start()+1:rsv.end()])
break
if is_nmap_found == False:
raise PortScannerError('nmap program was not found in path')
I found out that first regex is not working so I changed this:
from :
regex = re.compile('Nmap version [0-9]*\.[0-9]*[^ ]* \( http://nmap\.org \)')
to:
regex = re.compile('Nmap version [0-9]*\.[0-9]*)
Now it is working just like it suppose to work!