Home > Mobile >  Network scanner on Python
Network scanner on Python

Time:09-26

I am making a network scanner python project and have created below code by looking through youtube learning. But it is not working and giving an error. here is the code-

import nmap
 class network(object):
    def __init__(self):
        ip = input("Enter default IP address 10.10.1.1 10.10.0.1 ")
        self.ip = ip

    def networkscanner(self):
        if len(self.ip) == 0:
            network = '10.10.1.1/24'
        else:
            network = self.ip   '/24'

    print("Start scanning please wait....")

    nm = nmap.Portscanner()
    nm.scan(hosts=network, arguements='-sn')
    hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
    for host, status, in hosts_list:
        print("host \t{}".format(host))

    if __name__ == "__main__":
        D = network()
        D.networkscanner()

What I have understood that nmap dont have portscanner attributes but not sure though. I have imported python-nmap too and tried but still not working. Can anyone point me to the right direction please?

CodePudding user response:

According to the documentation, the correct call would be:

nm = nmap.PortScanner()

You have a lower case "s" instead of an upper case.

https://pypi.org/project/python-nmap/

CodePudding user response:

Ok, so I have managed to run the above code without any error, here are few things I did :

  1. Uninstall both nmap and python-nmap and re installed python-nmap
  2. correct some of the spelling and indentations

and voila! It worked.

  • Related