forked from p15670423/monkey
Agent: Sort scan targets by IP
This commit is contained in:
parent
c8469f5521
commit
ed16826b87
|
@ -1,5 +1,6 @@
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
import socket
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ def compile_scan_target_list(
|
||||||
scan_targets = _remove_interface_ips(scan_targets, local_network_interfaces)
|
scan_targets = _remove_interface_ips(scan_targets, local_network_interfaces)
|
||||||
scan_targets = _remove_blocklisted_ips(scan_targets, blocklisted_ips)
|
scan_targets = _remove_blocklisted_ips(scan_targets, blocklisted_ips)
|
||||||
scan_targets = _remove_redundant_targets(scan_targets)
|
scan_targets = _remove_redundant_targets(scan_targets)
|
||||||
scan_targets.sort()
|
scan_targets.sort(key=lambda network_address: socket.inet_aton(network_address.ip))
|
||||||
|
|
||||||
return scan_targets
|
return scan_targets
|
||||||
|
|
||||||
|
|
|
@ -466,3 +466,18 @@ def test_invalid_blocklisted_ip():
|
||||||
blocklisted_ips=blocklisted,
|
blocklisted_ips=blocklisted,
|
||||||
enable_local_network_scan=False,
|
enable_local_network_scan=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_sorted_scan_targets():
|
||||||
|
expected_results = [f"10.1.0.{i}" for i in range(0, 255)]
|
||||||
|
expected_results.extend([f"10.2.0.{i}" for i in range(0, 255)])
|
||||||
|
expected_results.extend([f"10.10.0.{i}" for i in range(0, 255)])
|
||||||
|
expected_results.extend([f"10.20.0.{i}" for i in range(0, 255)])
|
||||||
|
|
||||||
|
scan_targets = compile_scan_target_list(
|
||||||
|
[], ["10.1.0.0/24", "10.10.0.0/24", "10.20.0.0/24", "10.2.0.0/24"], [], [], False
|
||||||
|
)
|
||||||
|
|
||||||
|
actual_results = [network_address.ip for network_address in scan_targets]
|
||||||
|
|
||||||
|
assert expected_results == actual_results
|
||||||
|
|
Loading…
Reference in New Issue