From 2b55c35a65c28ba4f9585bb3e8659afbdca98085 Mon Sep 17 00:00:00 2001
From: Kekoa Kaaikala <kekoa.kaaikala@gmail.com>
Date: Mon, 29 Aug 2022 16:51:50 +0000
Subject: [PATCH] Agent: Use str() instead of .compressed

---
 monkey/infection_monkey/monkey.py                         | 6 +++---
 .../network_scanning/scan_target_generator.py             | 8 +++-----
 .../network_scanning/test_scan_target_generator.py        | 4 ++--
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py
index ff36ebb88..7fccc7616 100644
--- a/monkey/infection_monkey/monkey.py
+++ b/monkey/infection_monkey/monkey.py
@@ -239,10 +239,10 @@ class InfectionMonkey:
         )
 
     @staticmethod
-    def _get_local_network_interfaces():
+    def _get_local_network_interfaces() -> List[IPv4Interface]:
         local_network_interfaces = get_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
 
@@ -375,7 +375,7 @@ class InfectionMonkey:
 
     def _running_on_island(self, local_network_interfaces: List[IPv4Interface]) -> bool:
         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):
         return not self._singleton.try_lock()
diff --git a/monkey/infection_monkey/network_scanning/scan_target_generator.py b/monkey/infection_monkey/network_scanning/scan_target_generator.py
index b4f5e4238..a579aac2f 100644
--- a/monkey/infection_monkey/network_scanning/scan_target_generator.py
+++ b/monkey/infection_monkey/network_scanning/scan_target_generator.py
@@ -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(
     interfaces: List[IPv4Interface],
 ) -> List[NetworkAddress]:
-    ranges = [
-        f"{interface.ip.compressed}/{interface.network.prefixlen}" for interface in interfaces
-    ]
+    ranges = [f"{str(interface.ip)}/{interface.network.prefixlen}" for interface in interfaces]
 
     ranges = NetworkRange.filter_invalid_ranges(
         ranges, "Local network interface returns an invalid IP:"
@@ -92,7 +90,7 @@ def _get_ips_to_scan_from_local_interface(
 def _remove_interface_ips(
     scan_targets: List[NetworkAddress], interfaces: List[IPv4Interface]
 ) -> 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)
 
 
@@ -118,7 +116,7 @@ def _get_segmentation_check_targets(
     inaccessible_subnets: List[str], local_interfaces: List[IPv4Interface]
 ) -> List[NetworkAddress]:
     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: ")
     inaccessible_subnets = NetworkRange.filter_invalid_ranges(
diff --git a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_scan_target_generator.py b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_scan_target_generator.py
index 25e5f9ed3..82179b618 100644
--- a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_scan_target_generator.py
+++ b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_scan_target_generator.py
@@ -129,7 +129,7 @@ def test_local_network_interface_ips_removed_from_targets():
 
     assert len(scan_targets) == 252
     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():
@@ -192,7 +192,7 @@ def test_local_network_interface_ips_and_blocked_ips_removed_from_targets():
     )
 
     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:
         assert ip not in scan_targets