diff --git a/core/strategies/eye/picamera_strategy.py b/core/strategies/eye/picamera_strategy.py index 05a863c..8efae79 100644 --- a/core/strategies/eye/picamera_strategy.py +++ b/core/strategies/eye/picamera_strategy.py @@ -45,5 +45,4 @@ def get_frame(self) -> numpy.ndarray: logger.error( "An error occurred while capturing the frame: %s", error) raise RuntimeError from error - return cv2.rotate(frame, - cv2.ROTATE_90_COUNTERCLOCKWISE) + return frame diff --git a/core/strategies/wifi/ipaddress_strategy.py b/core/strategies/wifi/ipaddress_strategy.py index 2e30719..44fa749 100644 --- a/core/strategies/wifi/ipaddress_strategy.py +++ b/core/strategies/wifi/ipaddress_strategy.py @@ -2,9 +2,9 @@ The strategy which searches for IP addresses. """ from core.strategies.wifi.base_wifi_strategy import BaseWiFiStrategy -from core.utils.datatypes import WiFiStrategyResult +from core.utils.datatypes import ConnectedDeviceResult, WiFiStrategyResult from core.utils.logger import get_logger -from core.utils.program_launcher import PingCommands, run_program +from core.utils.program_launcher import ArpScanCommands, PingCommands, run_program # Add logging support. logger = get_logger(__name__) @@ -37,3 +37,12 @@ def check_protectors(self) -> WiFiStrategyResult: return WiFiStrategyResult(protector, True) logger.debug("No protectors found.") return WiFiStrategyResult(None, False) + + # Internal methods + def _get_all_connected(self) -> list[ConnectedDeviceResult]: + """This method returns a list of addresses of the clients connected to the network.""" + output = run_program(ArpScanCommands.GET_CONNECTED_IP_ADDRESSES) + ip_addrs = output.split('\n') + ip_addrs = ip_addrs[:-1] + logger.debug("Connected devices: %s", str(ip_addrs)) + return [ConnectedDeviceResult(mac_addr.upper()) for mac_addr in ip_addrs] diff --git a/core/utils/program_launcher.py b/core/utils/program_launcher.py index cf7b281..5682ae3 100644 --- a/core/utils/program_launcher.py +++ b/core/utils/program_launcher.py @@ -5,7 +5,7 @@ from enum import Enum -class ICommand(Enum, str): +class ICommand(str, Enum): """Interface for program commands.""" @@ -15,6 +15,8 @@ class ArpScanCommands(ICommand): INSTALL_PROGRAM = "sudo apt-get install arp-scan" GET_CONNECTED_MAC_ADDRESSES = "sudo arp-scan --localnet "\ "| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'" + GET_CONNECTED_IP_ADDRESSES = "sudo arp-scan --localnet "\ + "| grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'" class PingCommands(ICommand): diff --git a/hss.py b/hss.py index e7c64cf..b223471 100644 --- a/hss.py +++ b/hss.py @@ -14,7 +14,7 @@ from core.strategies.eye.picamera_strategy import PiCameraStrategy from core.strategies.notifier.telegram_strategy import TelegramStrategy from core.strategies.notifier.whatsapp_strategy import WhatsappStrategy -from core.strategies.wifi.admin_panel_strategy import AdminPanelStrategy +from core.strategies.wifi.ipaddress_strategy import IpAddressStrategy from core.utils.datatypes import Protector, TelegramReciever from core.utils.fileio_adaptor import upload_to_fileio @@ -44,7 +44,7 @@ def main(): reciever['chat_id'])) # Create a Protector within IpAddressStrategy. - network_strategy = AdminPanelStrategy(strategy_config['admin_panel_strategy']) + network_strategy = IpAddressStrategy() for protector in config['protectors']: network_strategy.add_protector(Protector(protector['name'], protector['address']))