Agent: Use str() instead of .compressed

This commit is contained in:
Kekoa Kaaikala 2022-08-29 16:51:50 +00:00
parent 01c508e248
commit 2b55c35a65
3 changed files with 8 additions and 10 deletions

View File

@ -239,10 +239,10 @@ class InfectionMonkey:
) )
@staticmethod @staticmethod
def _get_local_network_interfaces(): def _get_local_network_interfaces() -> List[IPv4Interface]:
local_network_interfaces = get_local_network_interfaces() local_network_interfaces = get_local_network_interfaces()
for i in local_network_interfaces: for i in local_network_interfaces:
logger.debug(f"Found local interface {i.ip.compressed}/{i.network.prefixlen}") logger.debug(f"Found local interface {str(i.ip)}/{i.network.prefixlen}")
return local_network_interfaces return local_network_interfaces
@ -375,7 +375,7 @@ class InfectionMonkey:
def _running_on_island(self, local_network_interfaces: List[IPv4Interface]) -> bool: def _running_on_island(self, local_network_interfaces: List[IPv4Interface]) -> bool:
server_ip, _ = address_to_ip_port(self._control_client.server_address) server_ip, _ = address_to_ip_port(self._control_client.server_address)
return server_ip in {interface.ip.compressed for interface in local_network_interfaces} return server_ip in {str(interface.ip) for interface in local_network_interfaces}
def _is_another_monkey_running(self): def _is_another_monkey_running(self):
return not self._singleton.try_lock() return not self._singleton.try_lock()

View File

@ -79,9 +79,7 @@ def _get_ips_from_ranges_to_scan(network_ranges: List[NetworkRange]) -> List[Net
def _get_ips_to_scan_from_local_interface( def _get_ips_to_scan_from_local_interface(
interfaces: List[IPv4Interface], interfaces: List[IPv4Interface],
) -> List[NetworkAddress]: ) -> List[NetworkAddress]:
ranges = [ ranges = [f"{str(interface.ip)}/{interface.network.prefixlen}" for interface in interfaces]
f"{interface.ip.compressed}/{interface.network.prefixlen}" for interface in interfaces
]
ranges = NetworkRange.filter_invalid_ranges( ranges = NetworkRange.filter_invalid_ranges(
ranges, "Local network interface returns an invalid IP:" ranges, "Local network interface returns an invalid IP:"
@ -92,7 +90,7 @@ def _get_ips_to_scan_from_local_interface(
def _remove_interface_ips( def _remove_interface_ips(
scan_targets: List[NetworkAddress], interfaces: List[IPv4Interface] scan_targets: List[NetworkAddress], interfaces: List[IPv4Interface]
) -> List[NetworkAddress]: ) -> List[NetworkAddress]:
interface_ips = [interface.ip.compressed for interface in interfaces] interface_ips = [str(interface.ip) for interface in interfaces]
return _remove_ips_from_scan_targets(scan_targets, interface_ips) return _remove_ips_from_scan_targets(scan_targets, interface_ips)
@ -118,7 +116,7 @@ def _get_segmentation_check_targets(
inaccessible_subnets: List[str], local_interfaces: List[IPv4Interface] inaccessible_subnets: List[str], local_interfaces: List[IPv4Interface]
) -> List[NetworkAddress]: ) -> List[NetworkAddress]:
ips_to_scan = [] ips_to_scan = []
local_ips = [interface.ip.compressed for interface in local_interfaces] local_ips = [str(interface.ip) for interface in local_interfaces]
local_ips = NetworkRange.filter_invalid_ranges(local_ips, "Invalid local IP found: ") local_ips = NetworkRange.filter_invalid_ranges(local_ips, "Invalid local IP found: ")
inaccessible_subnets = NetworkRange.filter_invalid_ranges( inaccessible_subnets = NetworkRange.filter_invalid_ranges(

View File

@ -129,7 +129,7 @@ def test_local_network_interface_ips_removed_from_targets():
assert len(scan_targets) == 252 assert len(scan_targets) == 252
for interface in local_network_interfaces: for interface in local_network_interfaces:
assert interface.ip.compressed not in scan_targets assert str(interface.ip) not in scan_targets
def test_no_redundant_targets(): def test_no_redundant_targets():
@ -192,7 +192,7 @@ def test_local_network_interface_ips_and_blocked_ips_removed_from_targets():
) )
for interface in local_network_interfaces: for interface in local_network_interfaces:
assert interface.ip.compressed not in scan_targets assert str(interface.ip) not in scan_targets
for ip in blocked_ips: for ip in blocked_ips:
assert ip not in scan_targets assert ip not in scan_targets