我正在制作一个网络扫描仪 python 项目,并通过查看 youtube 学习创建了以下代码。但它不起作用并给出错误。这是代码-
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, arguments='-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()
据我所知,nmap 没有 portscanner 属性,但不确定。我也导入了 python-nmap 并尝试但仍然无法正常工作。谁能指出我正确的方向?