Domanda

I have installed nmap.exe and the nmap module. I am not sure how to configure the nmap path though. The block of code where you enter the nmap path is as follows

class PortScanner(object):
"""
PortScanner class allows to use nmap from python

"""

def __init__(self, nmap_search_path=('nmap','/usr/bin/nmap','/usr/local/bin/nmap','/sw/bin/nmap','/opt/local/bin/nmap') ):
    """
    Initialize PortScanner module

    * detects nmap on the system and nmap version
    * may raise PortScannerError exception if nmap is not found in the path

    :param nmap_search_path: tupple of string where to search for nmap executable. Change this if you want to use a specific version of nmap.
    :returns: nothing

    """
    self._nmap_path = 'C:/Program Files (x86)/Nmap/'   # nmap path
    self._scan_result = {}
    self._nmap_version_number = 0       # nmap version number
    self._nmap_subversion_number = 0    # nmap subversion number
    self._nmap_last_output = ''  # last full ascii nmap output
    is_nmap_found = False       # true if we have found nmap

    self.__process = None

    # regex used to detect nmap
    regex = re.compile('Nmap version [0-9]*\.[0-9]*[^ ]* \( http://.* \)')
    # launch 'nmap -V', we wait after 'Nmap version 5.0 ( http://nmap.org )'
    # This is for Mac OSX. When idle3 is launched from the finder, PATH is not set so nmap was not found
    for nmap_path in nmap_search_path:
        try:
            p = subprocess.Popen([nmap_path, '-V'], bufsize=10000, stdout=subprocess.PIPE)
        except OSError:
            pass
        else:
            self._nmap_path = nmap_path # save path 
            break
    else:
        raise PortScannerError('nmap program was not found in path. PATH is : {0}'.format(os.getenv('PATH')))            

I placed the path in the self._nmap_path variable. However, it does not seem to work. Could anyone with experience in nmap help me? How do I get started in nmap? I have researched this for hours but have still not come up with an answer. The error I receive is

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    nmap.PortScanner()
  File "C:\Python33\Lib\site-packages\nmap\nmap.py", line 192, in __init__
    raise PortScannerError('nmap program was not found in path')
nmap.PortScannerError: 'nmap program was not found in path'
È stato utile?

Soluzione

It looks like your environment path is not setup correctly.

If you open the C:\Python33\Lib\site-packages\nmap\nmap.py file for editing and look at line 192. Where is it looking?

It might be worth simply reinstalling with the self installer, the installer should set the path variables for you.

http://nmap.org/book/inst-windows.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top