Error with Python Nmap

Asked

Viewed 206 times

2

I’m trying to make a script on python using the Python nmap, but I keep getting an error on the console when I try to run the script!

My code:

import nmap
import os

nmScan = nmap.PortScanner()

def OS():
    os.system('cls' if os.name == 'nt' else 'clear')

def menu():

    global menuoption
    global ipaddr
    global port
    global state

    OS()

    print("Welcome to Python-Nmap Scanner made by DeAdSeC")
    print("----------------------------------------------")
    print("What type of scan would you like to run?")
    print("1) Full Network Scan")
    print("2) TPC Scan")
    print("3) UDP Scan")
    print("4) Scan for a specified port")

    menuoption = int(input())

    if menuoption == 1:
        OS()
        ipaddr = input("Please enter your ip address: ")
        state = nmScan[ipaddr].state()

        print(state)

    if menuoption == 2:
        OS()
        ipaddr = input("Please enter your ip address: ")
        OS()
        print("Colected data:")
        print("--------------")
        print("Ip Status: ", nmScan[ipaddr].state())

    if menuoption == 3:
        OS()
        ipaddr = input("Please enter your ip address: ")
    if menuoption == 4:
        OS()
        ipaddr = input("Please enter your ip address: ")
        OS()
        port = input("Please enter the port you wanna scan: ")
    else:
        OS()
        print("You fucked up a simple shit!")
        return menu()


menu()

ERROR:

Colected data:
--------------
Traceback (most recent call last):
  File "scanner.py", line 57, in <module>
    menu()
  File "scanner.py", line 41, in menu
    print("Ip Status: ", nmScan[ipaddr].state())
  File "/usr/local/lib/python3.6/dist-packages/nmap/nmap.py", line 501, in __getitem__
    return self._scan_result['scan'][host]
KeyError: 'scan'
  • It seems on the line nmScan[ipaddr].state() you are using an ip that does not exist. You are sure that you are searching for an ip that exists in the returned by nmScan.all_hosts() ?

  • @Isac finally managed to solve the problem alone but thanks anyway!

  • @Deadsec If solved, you can publish the solution as a response?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.