mirror of
https://github.com/nmap/nmap.git
synced 2025-12-11 10:19:03 +00:00
Don't ignore host state changes when the change is to the state "unknown". This
happens when a host was scanned in the A scan but wasn't scanned in the B scan. I previously had it ignore such changes using the logic that the diff should be like scan aggregation: no new information means no state change. But I think it's more useful to see those changes in which hosts were scanned. This is analogous to r10263, which did the same thing for port state changes.
This commit is contained in:
@@ -36,6 +36,12 @@ Here is a sample of the text output:
|
|||||||
Add ipv4 address 10.242.160.155.
|
Add ipv4 address 10.242.160.155.
|
||||||
Add hostname ywnleu-108.example.com.
|
Add hostname ywnleu-108.example.com.
|
||||||
1000 tcp ports are filtered.
|
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:
|
Here is an abbreviated sample of the XML output:
|
||||||
|
|
||||||
|
|||||||
@@ -447,7 +447,6 @@ def scan_diff(a, b):
|
|||||||
for id in all_host_ids:
|
for id in all_host_ids:
|
||||||
host_a = a_hosts.get(id)
|
host_a = a_hosts.get(id)
|
||||||
host_b = b_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())
|
h_diff = host_diff(host_a or Host(), host_b or Host())
|
||||||
if len(h_diff) > 0:
|
if len(h_diff) > 0:
|
||||||
diff.append((host_a or host_b, h_diff))
|
diff.append((host_a or host_b, h_diff))
|
||||||
|
|||||||
@@ -487,7 +487,7 @@ class scan_diff_test(unittest.TestCase):
|
|||||||
for host, h_diff in diff:
|
for host, h_diff in diff:
|
||||||
for hunk in h_diff:
|
for hunk in h_diff:
|
||||||
if hunk.type == HOST_STATE_CHANGE:
|
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")
|
self.assertTrue(hunk.b_state == u"up")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -499,7 +499,14 @@ class scan_diff_test(unittest.TestCase):
|
|||||||
b = Scan()
|
b = Scan()
|
||||||
b.load_from_file("test-scans/empty.xml")
|
b.load_from_file("test-scans/empty.xml")
|
||||||
diff = scan_diff(a, b)
|
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):
|
def test_diff_is_effective(self):
|
||||||
"""Test that a scan diff is effective.
|
"""Test that a scan diff is effective.
|
||||||
|
|||||||
Reference in New Issue
Block a user