# Ndiff
#
-@@ -26,11 +26,11 @@ xml.__path__ = [x for x in xml.__path__
+@@ -25,11 +25,11 @@ xml.__path__ = [x for x in xml.__path__
import xml.sax
import xml.sax.saxutils
import xml.dom.minidom
class OverrideEntityResolver(xml.sax.handler.EntityResolver):
-@@ -75,35 +75,35 @@ class Scan(object):
+@@ -74,35 +74,35 @@ class Scan(object):
def write_nmaprun_open(self, writer):
attrs = {}
if self.scanner is not None:
frag.appendChild(elem)
return frag
-@@ -133,17 +133,17 @@ class Host(object):
+@@ -132,17 +132,17 @@ class Host(object):
def format_name(self):
"""Return a human-readable identifier for this host."""
def add_port(self, port):
self.ports[port.spec] = port
-@@ -160,46 +160,46 @@ class Host(object):
+@@ -159,46 +159,46 @@ class Host(object):
return state is None or state in self.extraports
def extraports_string(self):
if self.state is not None:
elem.appendChild(self.state_to_dom_fragment(document))
-@@ -208,13 +208,13 @@ class Host(object):
+@@ -207,13 +207,13 @@ class Host(object):
elem.appendChild(addr.to_dom_fragment(document))
if len(self.hostnames) > 0:
ports_elem.appendChild(self.extraports_to_dom_fragment(document))
for port in sorted(self.ports.values()):
if not self.is_extraports(port.state):
-@@ -223,13 +223,13 @@ class Host(object):
+@@ -222,13 +222,13 @@ class Host(object):
elem.appendChild(ports_elem)
if len(self.os) > 0:
for sr in self.script_results:
hostscript_elem.appendChild(sr.to_dom_fragment(document))
elem.appendChild(hostscript_elem)
-@@ -243,7 +243,7 @@ class Address(object):
+@@ -242,7 +242,7 @@ class Address(object):
self.s = s
def __eq__(self, other):
def __ne__(self, other):
return not self.__eq__(other)
-@@ -251,8 +251,8 @@ class Address(object):
+@@ -250,8 +250,8 @@ class Address(object):
def __hash__(self):
return hash(self.sort_key())
def __str__(self):
return str(self.s)
-@@ -261,21 +261,21 @@ class Address(object):
+@@ -260,21 +260,21 @@ class Address(object):
return self.s
def new(type, s):
frag.appendChild(elem)
return frag
-@@ -284,21 +284,21 @@ class Address(object):
+@@ -283,21 +283,21 @@ class Address(object):
class IPv4Address(Address):
def sort_key(self):
return (2, self.s)
-@@ -317,31 +317,28 @@ class Port(object):
+@@ -316,31 +316,28 @@ class Port(object):
def state_string(self):
if self.state is None:
elem.appendChild(state_elem)
elem.appendChild(self.service.to_dom_fragment(document))
for sr in self.script_results:
-@@ -385,7 +382,7 @@ class Service(object):
+@@ -384,7 +381,7 @@ class Service(object):
if len(parts) == 0:
return None
else:
def version_string(self):
"""Get a string like in the VERSION column of Nmap output."""
-@@ -395,17 +392,17 @@ class Service(object):
+@@ -394,17 +391,17 @@ class Service(object):
if self.version is not None:
parts.append(self.version)
if self.extrainfo is not None:
v = getattr(self, attr)
if v is None:
continue
-@@ -435,53 +432,53 @@ class ScriptResult(object):
+@@ -434,53 +431,53 @@ class ScriptResult(object):
result = []
lines = self.output.splitlines()
if len(lines) > 0:
def script_result_diffs_to_dom_fragment(elem, script_results_a,
-@@ -489,13 +486,13 @@ def script_result_diffs_to_dom_fragment(
+@@ -488,13 +485,13 @@ def script_result_diffs_to_dom_fragment(
if len(script_results_a) == 0 and len(script_results_b) == 0:
return document.createDocumentFragment()
elif len(script_results_b) == 0:
for sr in script_results_b:
elem.appendChild(sr.to_dom_fragment(document))
b_elem.appendChild(elem)
-@@ -580,10 +577,10 @@ class ScanDiffText(ScanDiff):
+@@ -579,10 +576,10 @@ class ScanDiffText(ScanDiff):
banner_a = format_banner(self.scan_a)
banner_b = format_banner(self.scan_b)
if banner_a != banner_b:
def output_pre_scripts(self, pre_script_result_diffs):
print_script_result_diffs_text("Pre-scan script results",
-@@ -596,7 +593,7 @@ class ScanDiffText(ScanDiff):
+@@ -595,7 +592,7 @@ class ScanDiffText(ScanDiff):
post_script_result_diffs, self.f)
def output_host_diff(self, h_diff):
h_diff.print_text(self.f)
def output_ending(self):
-@@ -621,8 +618,8 @@ class ScanDiffXML(ScanDiff):
+@@ -620,8 +617,8 @@ class ScanDiffXML(ScanDiff):
def output_beginning(self):
self.writer.startDocument()
if self.nmaprun_differs():
self.writer.frag_a(
-@@ -635,7 +632,7 @@ class ScanDiffXML(ScanDiff):
+@@ -634,7 +631,7 @@ class ScanDiffXML(ScanDiff):
def output_pre_scripts(self, pre_script_result_diffs):
if len(pre_script_result_diffs) > 0 or verbose:
frag = script_result_diffs_to_dom_fragment(
prescript_elem, self.scan_a.pre_script_results,
self.scan_b.pre_script_results, pre_script_result_diffs,
-@@ -645,7 +642,7 @@ class ScanDiffXML(ScanDiff):
+@@ -644,7 +641,7 @@ class ScanDiffXML(ScanDiff):
def output_post_scripts(self, post_script_result_diffs):
if len(post_script_result_diffs) > 0 or verbose:
frag = script_result_diffs_to_dom_fragment(
postscript_elem, self.scan_a.post_script_results,
self.scan_b.post_script_results, post_script_result_diffs,
-@@ -659,8 +656,8 @@ class ScanDiffXML(ScanDiff):
+@@ -658,8 +655,8 @@ class ScanDiffXML(ScanDiff):
frag.unlink()
def output_ending(self):
self.writer.endDocument()
-@@ -718,9 +715,9 @@ class HostDiff(object):
+@@ -717,9 +714,9 @@ class HostDiff(object):
self.cost += os_cost
extraports_a = tuple((count, state)
if extraports_a != extraports_b:
self.extraports_changed = True
self.cost += 1
-@@ -746,69 +743,69 @@ class HostDiff(object):
+@@ -745,69 +742,69 @@ class HostDiff(object):
# Names and addresses.
if self.id_changed:
if host_a.state is not None:
print_script_result_diffs_text("Host script results",
host_a.script_results, host_b.script_results,
-@@ -819,32 +816,32 @@ class HostDiff(object):
+@@ -818,32 +815,32 @@ class HostDiff(object):
host_b = self.host_b
frag = document.createDocumentFragment()
b_elem.appendChild(host_b.state_to_dom_fragment(document))
host_elem.appendChild(b_elem)
-@@ -853,31 +850,31 @@ class HostDiff(object):
+@@ -852,31 +849,31 @@ class HostDiff(object):
addrset_b = set(host_b.addresses)
for addr in sorted(addrset_a.intersection(addrset_b)):
host_elem.appendChild(addr.to_dom_fragment(document))
for hostname in sorted(hostnameset_b - hostnameset_a):
b_elem.appendChild(
host_b.hostname_to_dom_fragment(document, hostname))
-@@ -886,15 +883,15 @@ class HostDiff(object):
+@@ -885,15 +882,15 @@ class HostDiff(object):
if hostnames_elem.hasChildNodes():
host_elem.appendChild(hostnames_elem)
b_elem.appendChild(host_b.extraports_to_dom_fragment(document))
ports_elem.appendChild(b_elem)
# Port list.
-@@ -910,18 +907,18 @@ class HostDiff(object):
+@@ -909,18 +906,18 @@ class HostDiff(object):
# OS changes.
if self.os_changed or verbose:
for i in range(j1, j2):
b_elem.appendChild(host_b.os_to_dom_fragment(
document, host_b.os[i]))
-@@ -935,7 +932,7 @@ class HostDiff(object):
+@@ -934,7 +931,7 @@ class HostDiff(object):
# Host script changes.
if len(self.script_result_diffs) > 0 or verbose:
host_elem.appendChild(script_result_diffs_to_dom_fragment(
hostscript_elem, host_a.script_results,
host_b.script_results, self.script_result_diffs,
-@@ -988,38 +985,38 @@ class PortDiff(object):
+@@ -987,38 +984,38 @@ class PortDiff(object):
self.port_b.service.version_string()]
if a_columns == b_columns:
if verbose or self.script_result_diffs > 0:
b_elem.appendChild(
self.port_b.service.to_dom_fragment(document))
port_elem.appendChild(b_elem)
-@@ -1027,10 +1024,10 @@ class PortDiff(object):
+@@ -1026,10 +1023,10 @@ class PortDiff(object):
port_elem.appendChild(sr_diff.to_dom_fragment(document))
portdiff_elem.appendChild(port_elem)
else:
b_elem.appendChild(self.port_b.to_dom_fragment(document))
portdiff_elem.appendChild(b_elem)
-@@ -1085,13 +1082,13 @@ class ScriptResultDiff(object):
+@@ -1084,13 +1081,13 @@ class ScriptResultDiff(object):
for op, i1, i2, j1, j2 in diffs.get_opcodes():
if op == "replace" or op == "delete":
for k in range(i1, i2):
def to_dom_fragment(self, document):
frag = document.createDocumentFragment()
-@@ -1101,11 +1098,11 @@ class ScriptResultDiff(object):
+@@ -1100,11 +1097,11 @@ class ScriptResultDiff(object):
frag.appendChild(self.sr_a.to_dom_fragment(document))
else:
if self.sr_a is not None:
b_elem.appendChild(self.sr_b.to_dom_fragment(document))
frag.appendChild(b_elem)
return frag
-@@ -1119,7 +1116,7 @@ class Table(object):
+@@ -1118,7 +1115,7 @@ class Table(object):
copied to the output."""
self.widths = []
self.rows = []
self.padding = []
j = 0
while j < len(template) and template[j] != "*":
-@@ -1144,7 +1141,7 @@ class Table(object):
+@@ -1143,7 +1140,7 @@ class Table(object):
for i in range(len(row)):
if row[i] is None:
else:
s = str(row[i])
if i == len(self.widths):
-@@ -1166,7 +1163,7 @@ class Table(object):
+@@ -1165,7 +1162,7 @@ class Table(object):
for row in self.rows:
parts = [self.prefix]
i = 0
# A raw string.
lines.append(row)
else:
-@@ -1175,13 +1172,13 @@ class Table(object):
+@@ -1174,13 +1171,13 @@ class Table(object):
if i < len(self.padding):
parts.append(self.padding[i])
i += 1
class NmapContentHandler(xml.sax.handler.ContentHandler):
-@@ -1201,24 +1198,24 @@ class NmapContentHandler(xml.sax.handler
+@@ -1200,24 +1197,24 @@ class NmapContentHandler(xml.sax.handler
self.skip_over = False
self._start_elem_handlers = {
}
def parent_element(self):
-@@ -1248,72 +1245,72 @@ class NmapContentHandler(xml.sax.handler
+@@ -1247,72 +1244,72 @@ class NmapContentHandler(xml.sax.handler
def _start_nmaprun(self, name, attrs):
assert self.parent_element() is None
if "start" in attrs:
'attribute; assuming 0.' % (
name, self.current_host.format_name()))
count = 0
-@@ -1321,99 +1318,99 @@ class NmapContentHandler(xml.sax.handler
+@@ -1320,99 +1317,99 @@ class NmapContentHandler(xml.sax.handler
try:
count = int(count)
except ValueError:
self.scan.end_date = datetime.datetime.fromtimestamp(end_timestamp)
def _end_host(self, name):
-@@ -1435,23 +1432,23 @@ class XMLWriter (xml.sax.saxutils.XMLGen
+@@ -1434,23 +1431,23 @@ class XMLWriter (xml.sax.saxutils.XMLGen
def frag(self, frag):
for node in frag.childNodes:
Usage: %s [option] FILE1 FILE2
Compare two Nmap XML files and display a list of their differences.
Differences include host state changes, port state changes, and changes to
-@@ -1461,7 +1458,7 @@ service and OS detection.
+@@ -1460,7 +1457,7 @@ service and OS detection.
-v, --verbose also show hosts and ports that haven't changed.
--text display output in text format (default)
--xml display output in XML format\
EXIT_EQUAL = 0
EXIT_DIFFERENT = 1
-@@ -1469,8 +1466,8 @@ EXIT_ERROR = 2
+@@ -1468,8 +1465,8 @@ EXIT_ERROR = 2
def usage_error(msg):
sys.exit(EXIT_ERROR)
-@@ -1481,7 +1478,7 @@ def main():
+@@ -1480,7 +1477,7 @@ def main():
try:
opts, input_filenames = getopt.gnu_getopt(
sys.argv[1:], "hv", ["help", "text", "verbose", "xml"])
usage_error(e.msg)
for o, a in opts:
if o == "-h" or o == "--help":
-@@ -1491,15 +1488,15 @@ def main():
+@@ -1490,15 +1487,15 @@ def main():
verbose = True
elif o == "--text":
if output_format is not None and output_format != "text":
if output_format is None:
output_format = "text"
-@@ -1512,8 +1509,8 @@ def main():
+@@ -1511,8 +1508,8 @@ def main():
scan_a.load_from_file(filename_a)
scan_b = Scan()
scan_b.load_from_file(filename_b)
# Ndiff
#
-@@ -67,15 +67,15 @@ if INSTALL_LIB is not None and is_secure
+@@ -66,15 +66,15 @@ if INSTALL_LIB is not None and is_secure
try:
import ndiff