Island: Style improvements in ip_addresses.py

This commit is contained in:
vakarisz 2022-06-16 12:39:03 +03:00
parent 5fbe01a32e
commit 0082cd2193
2 changed files with 7 additions and 4 deletions

View File

@ -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()

View File

@ -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, [])