('Nmap not found', )

后端 未结 8 1063
难免孤独
难免孤独 2020-12-18 04:28

Where is the problem?

import nmap

I installed nmap and python, and when I use import nmap there is no any problem. But when us

相关标签:
8条回答
  • 2020-12-18 04:51

    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

    pip uninstall python-nmap
    

    If you are unsure if Nmap binaries are installed on your current system, do a simple search for

    nmap
    

    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

    My PC > System Information > Advance settings > Environment Variables
    

    Or right click

    My PC or My Computer or whatever yours is called and select properties then advance settings then Environment Variables at the bottom of the Advanced tab

    select Path for both You and the System

    press Edit and enter the full 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 your ide and test your code again.

    0 讨论(0)
  • 2020-12-18 04:51

    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:

    def ping(self, ip):
        # Use the system ping command with count of 1 and wait time of 1.
        ret = subprocess.call(['ping', '-c', '1', '-W', '1', ip],
                              stdout=open('/dev/null', 'w'),
                              stderr=open('/dev/null', 'w'))
    
        return ret == 0 # Return True if our ping command succeeds
    

    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)

    class IpInfo(object):
    ip = None
    hostname = None
    ports = []
    lastSeenAt = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    
    
    def findHostName(self):
        if(ip):
            self.hostname = str(socket.gethostbyaddr(ip)[0])
        else:
            raise NameError('IP missing')
    
    def findOpenPorts(self):
        print('findOpenPorts')
        nm = nmap.PortScanner()
        nm.scan(host)
        nm.command_line()
        nm.scaninfo()
    
        for proto in nm[self.ip].all_protocols():
            print('----------')
            print('Protocol : %s' % proto)
    
            lport = nm[self.ip][proto].keys()   #<------ This 'proto' was changed from the [proto] to the ['tcp'].
            lport.sort()
    
            for port in lport:
                if(nm[self.ip][proto][port]['state'] == 'open'):
                    self.ports.append(port)
    
    0 讨论(0)
  • 2020-12-18 04:53

    python-nmap seems to depend on nmap, 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:

     which nmap
    

    Debian-like

    You can install nmap in debian-like distros with:

    apt-get install nmap
    

    Arch linux:

    pacman -Sy nmap
    

    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:

    export PATH="$PATH:/usr/local/nmap/bin"
    

    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 type exec bash to refresh it.

    You also have to make sure, that it has execute permission (chmod +x <file>).

    When you execute:

    nmap --version
    

    You should see something like this:

    Nmap version 6.46 ( http://nmap.org )
    Platform: i686-pc-linux-gnu
    Compiled with: liblua-5.2.3 openssl-1.0.1g libpcre-8.34 libpcap-1.5.3 nmap-libdnet-1.12 ipv6
    Compiled without:
    Available nsock engines: epoll poll select
    

    If you do, nmap is installed and in your $PATH.

    0 讨论(0)
  • 2020-12-18 04:55

    for macOS user simply use brew install nmap instead of using pip

    0 讨论(0)
  • 2020-12-18 04:56

    I have had the same problem. Just type in a terminal:

    sudo apt-get install nmap
    

    and problem solved.

    0 讨论(0)
  • 2020-12-18 05:00

    Under windows, you must first install nmap for windows, you can install with this link https://nmap.org/download.html

    0 讨论(0)
提交回复
热议问题