diff --git a/monkey/infection_monkey/network/scan_target_generator.py b/monkey/infection_monkey/network/scan_target_generator.py index 0aac33cc9..41b570622 100644 --- a/monkey/infection_monkey/network/scan_target_generator.py +++ b/monkey/infection_monkey/network/scan_target_generator.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Set from common.network.network_range import NetworkRange @@ -10,16 +10,18 @@ def compile_scan_target_list( blocklisted_ips: List[str], enable_local_network_scan: bool, ) -> List[str]: - scan_target_list = _get_ips_from_ranges_to_scan(ranges_to_scan) + scan_targets = _get_ips_from_ranges_to_scan(ranges_to_scan) + scan_target_list = list(scan_targets) + scan_target_list.sort() return scan_target_list -def _get_ips_from_ranges_to_scan(ranges_to_scan): - scan_target_list = [] +def _get_ips_from_ranges_to_scan(ranges_to_scan: List[str]) -> Set[str]: + scan_targets = set() network_ranges = [NetworkRange.get_range_obj(_range) for _range in ranges_to_scan] for _range in network_ranges: - scan_target_list.extend([ip for ip in _range]) + scan_targets.update(set(_range)) - return scan_target_list + return scan_targets