mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
Merge #2088: Update Zenmap to Python 3 and PyGObject
Note: Ndiff build will be broken until subsequent changes are made. Deprecation warnings will need to be addressed in future changes. Closes #2088
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# ***********************IMPORTANT NMAP LICENSE TERMS************************
|
||||
# * *
|
||||
@@ -63,7 +62,7 @@ import unittest
|
||||
import zenmapCore
|
||||
import zenmapCore.NmapParser
|
||||
from zenmapGUI.SearchGUI import SearchParser
|
||||
from SearchResult import HostSearch
|
||||
from .SearchResult import HostSearch
|
||||
|
||||
|
||||
class NetworkInventory(object):
|
||||
@@ -255,13 +254,13 @@ class NetworkInventory(object):
|
||||
return self.scans
|
||||
|
||||
def get_hosts(self):
|
||||
return self.hosts.values()
|
||||
return list(self.hosts.values())
|
||||
|
||||
def get_hosts_up(self):
|
||||
return filter(lambda h: h.get_state() == 'up', self.hosts.values())
|
||||
return [h for h in list(self.hosts.values()) if h.get_state() == 'up']
|
||||
|
||||
def get_hosts_down(self):
|
||||
return filter(lambda h: h.get_state() == 'down', self.hosts.values())
|
||||
return [h for h in list(self.hosts.values()) if h.get_state() == 'down']
|
||||
|
||||
def open_from_file(self, path):
|
||||
"""Loads a scan from the given file."""
|
||||
@@ -353,7 +352,7 @@ class NetworkInventory(object):
|
||||
a list of (full-path) filenames that were used to save the scans."""
|
||||
self._generate_filenames(path)
|
||||
|
||||
for scan, filename in self.filenames.iteritems():
|
||||
for scan, filename in self.filenames.items():
|
||||
f = open(os.path.join(path, filename), "w")
|
||||
scan.write_xml(f)
|
||||
f.close()
|
||||
@@ -367,7 +366,7 @@ class NetworkInventory(object):
|
||||
# For now, this saves each scan making up the inventory separately in
|
||||
# the database.
|
||||
from time import time
|
||||
from cStringIO import StringIO
|
||||
from io import StringIO
|
||||
from zenmapCore.UmitDB import Scans
|
||||
|
||||
for parsed in self.get_scans():
|
||||
@@ -424,15 +423,13 @@ class FilteredNetworkInventory(NetworkInventory):
|
||||
|
||||
def get_hosts_up(self):
|
||||
if len(self.search_dict) > 0:
|
||||
return filter(lambda h: h.get_state() == 'up',
|
||||
self.filtered_hosts)
|
||||
return [h for h in self.filtered_hosts if h.get_state() == 'up']
|
||||
else:
|
||||
return NetworkInventory.get_hosts_up(self)
|
||||
|
||||
def get_hosts_down(self):
|
||||
if len(self.search_dict) > 0:
|
||||
return filter(lambda h: h.get_state() == 'down',
|
||||
self.filtered_hosts)
|
||||
return [h for h in self.filtered_hosts if h.get_state() == 'down']
|
||||
else:
|
||||
return NetworkInventory.get_hosts_down(self)
|
||||
|
||||
@@ -508,10 +505,10 @@ class FilteredNetworkInventory(NetworkInventory):
|
||||
self.filter_text = filter_text.lower()
|
||||
self.search_parser.update(self.filter_text)
|
||||
self.filtered_hosts = []
|
||||
for hostname, host in self.hosts.iteritems():
|
||||
for hostname, host in self.hosts.items():
|
||||
# For each host in this scan
|
||||
# Test each given operator against the current host
|
||||
for operator, args in self.search_dict.iteritems():
|
||||
for operator, args in self.search_dict.items():
|
||||
if not self._match_all_args(host, operator, args):
|
||||
# No match => we discard this scan_result
|
||||
break
|
||||
@@ -582,7 +579,7 @@ class NetworkInventoryTest(unittest.TestCase):
|
||||
inv.remove_scan(scan_3)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertEqual(added_ips, inv.hosts.keys())
|
||||
self.assertEqual(added_ips, list(inv.hosts.keys()))
|
||||
self.assertEqual(host_a.hostnames, ["a"])
|
||||
self.assertEqual(host_b.hostnames, ["b"])
|
||||
|
||||
@@ -646,7 +643,7 @@ if __name__ == "__main__":
|
||||
inventory1.add_scan(scan2)
|
||||
|
||||
for host in inventory1.get_hosts():
|
||||
print "%s" % host.ip["addr"],
|
||||
print("%s" % host.ip["addr"], end=' ')
|
||||
#if len(host.hostnames) > 0:
|
||||
# print "[%s]:" % host.hostnames[0]["hostname"]
|
||||
#else:
|
||||
@@ -662,12 +659,12 @@ if __name__ == "__main__":
|
||||
inventory1.remove_scan(scan2)
|
||||
print
|
||||
for host in inventory1.get_hosts():
|
||||
print "%s" % host.ip["addr"],
|
||||
print("%s" % host.ip["addr"], end=' ')
|
||||
|
||||
inventory1.add_scan(scan2)
|
||||
print
|
||||
for host in inventory1.get_hosts():
|
||||
print "%s" % host.ip["addr"],
|
||||
print("%s" % host.ip["addr"], end=' ')
|
||||
|
||||
dir = "/home/ndwi/scanz/top01"
|
||||
inventory1.save_to_dir(dir)
|
||||
@@ -675,6 +672,6 @@ if __name__ == "__main__":
|
||||
inventory2 = NetworkInventory()
|
||||
inventory2.open_from_dir(dir)
|
||||
|
||||
print
|
||||
print()
|
||||
for host in inventory2.get_hosts():
|
||||
print "%s" % host.ip["addr"],
|
||||
print("%s" % host.ip["addr"], end=' ')
|
||||
|
||||
Reference in New Issue
Block a user