diff --git a/ndiff/README b/ndiff/README index 5dd6fa4b2..ac7861422 100644 --- a/ndiff/README +++ b/ndiff/README @@ -36,6 +36,12 @@ Here is a sample of the text output: Add ipv4 address 10.242.160.155. Add hostname ywnleu-108.example.com. 1000 tcp ports are filtered. + fiyrownc-307.example.com (10.65.53.252): + Host is unknown, was up. + Remove ipv4 address 10.65.53.252. + Remove hostname fiyrownc-307.example.com. + 8089/tcp is unknown, was open. + 999 tcp ports changed state from filtered to unknown. Here is an abbreviated sample of the XML output: diff --git a/ndiff/ndiff b/ndiff/ndiff index 7691bc65d..898a5574a 100755 --- a/ndiff/ndiff +++ b/ndiff/ndiff @@ -447,10 +447,9 @@ def scan_diff(a, b): for id in all_host_ids: host_a = a_hosts.get(id) host_b = b_hosts.get(id) - if host_b is not None and host_b.state != Host.UNKNOWN: - h_diff = host_diff(host_a or Host(), host_b or Host()) - if len(h_diff) > 0: - diff.append((host_a or host_b, h_diff)) + h_diff = host_diff(host_a or Host(), host_b or Host()) + if len(h_diff) > 0: + diff.append((host_a or host_b, h_diff)) return diff def warn(str): diff --git a/ndiff/ndifftest.py b/ndiff/ndifftest.py index 8c9b129d6..fa1d2e399 100755 --- a/ndiff/ndifftest.py +++ b/ndiff/ndifftest.py @@ -487,7 +487,7 @@ class scan_diff_test(unittest.TestCase): for host, h_diff in diff: for hunk in h_diff: if hunk.type == HOST_STATE_CHANGE: - self.assertTrue(hunk.a_state == Port.UNKNOWN) + self.assertTrue(hunk.a_state == Host.UNKNOWN) self.assertTrue(hunk.b_state == u"up") break else: @@ -499,7 +499,14 @@ class scan_diff_test(unittest.TestCase): b = Scan() b.load_from_file("test-scans/empty.xml") diff = scan_diff(a, b) - self.assertTrue(len(diff) == 0) + for host, h_diff in diff: + for hunk in h_diff: + if hunk.type == HOST_STATE_CHANGE: + self.assertTrue(hunk.a_state == u"up") + self.assertTrue(hunk.b_state == Port.UNKNOWN) + break + else: + fail("No host state change found.") def test_diff_is_effective(self): """Test that a scan diff is effective.