From 0082cd21934b341d4e4922790c58f9a64d25e0ab Mon Sep 17 00:00:00 2001 From: vakarisz Date: Thu, 16 Jun 2022 12:39:03 +0300 Subject: [PATCH] Island: Style improvements in ip_addresses.py --- monkey/monkey_island/cc/resources/ip_addresses.py | 8 +++++--- monkey/monkey_island/cc/services/utils/network_utils.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/monkey/monkey_island/cc/resources/ip_addresses.py b/monkey/monkey_island/cc/resources/ip_addresses.py index 6f031d24f..ef0e0fa4b 100644 --- a/monkey/monkey_island/cc/resources/ip_addresses.py +++ b/monkey/monkey_island/cc/resources/ip_addresses.py @@ -1,3 +1,5 @@ +from typing import Mapping, Sequence + from monkey_island.cc.resources.AbstractResource import AbstractResource from monkey_island.cc.resources.request_authentication import jwt_required from monkey_island.cc.services.utils.network_utils import local_ip_addresses @@ -7,11 +9,11 @@ class IpAddresses(AbstractResource): urls = ["/api/island/ip-addresses"] @jwt_required - def get(self): + def get(self) -> Mapping[str, Sequence[str]]: """ - Gets the local ip address from the Island + Gets the IP addresses of the Island network interfaces - :return: a list of local ips + :return: a dictionary with "ip_addresses" key that points to a list of IP's """ local_ips = local_ip_addresses() diff --git a/monkey/monkey_island/cc/services/utils/network_utils.py b/monkey/monkey_island/cc/services/utils/network_utils.py index 3aa204ee3..bdd2cc404 100644 --- a/monkey/monkey_island/cc/services/utils/network_utils.py +++ b/monkey/monkey_island/cc/services/utils/network_utils.py @@ -3,6 +3,7 @@ import ipaddress import socket import struct import sys +from typing import Sequence from netifaces import AF_INET, ifaddresses, interfaces from ring import lru @@ -60,7 +61,7 @@ else: # This means that if the interfaces of the Island machine change, the Island process needs to be # restarted. @lru(maxsize=1) -def local_ip_addresses(): +def local_ip_addresses() -> Sequence[str]: ip_list = [] for interface in interfaces(): addresses = ifaddresses(interface).get(AF_INET, [])