mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
Make NmapOutputViewer.go_to_host more efficient
Instead of loading the entire output into a new string with gtk.TextBuffer.get_text, we use the gtk.TextIter.forward_search method. This works because we don't need to use regular expressions to find a static string.
This commit is contained in:
@@ -216,16 +216,14 @@ class NmapOutputViewer (gtk.VBox):
|
|||||||
def go_to_host(self, host):
|
def go_to_host(self, host):
|
||||||
"""Go to host line on nmap output result"""
|
"""Go to host line on nmap output result"""
|
||||||
buff = self.text_view.get_buffer()
|
buff = self.text_view.get_buffer()
|
||||||
start_iter, end_iter = buff.get_bounds()
|
start_iter = buff.get_start_iter()
|
||||||
|
|
||||||
output = buff.get_text(start_iter, end_iter).split("\n")
|
found = start_iter.forward_search(
|
||||||
re_host = re.compile(r'^Nmap scan report for %s\s*$' % re.escape(host))
|
"\nNmap scan report for %s\n" % host, gtk.TEXT_SEARCH_TEXT_ONLY
|
||||||
|
)[0]
|
||||||
for i in xrange(len(output)):
|
if not found.forward_line():
|
||||||
if re_host.match(output[i]):
|
return
|
||||||
self.text_view.scroll_to_iter(
|
self.text_view.scroll_to_iter(found, 0, True, 0, 0)
|
||||||
buff.get_iter_at_line(i), 0, True, 0, 0)
|
|
||||||
break
|
|
||||||
|
|
||||||
def show_output_properties(self, widget):
|
def show_output_properties(self, widget):
|
||||||
nmap_out_prop = NmapOutputProperties(self.text_view)
|
nmap_out_prop = NmapOutputProperties(self.text_view)
|
||||||
|
|||||||
Reference in New Issue
Block a user