Common: Add get_my_ip_addresses() -> Sequence[IPv4Address]

This commit is contained in:
Mike Salvatore 2022-09-23 08:13:20 -04:00
parent a89d76a4c5
commit fc4c05405b
1 changed files with 6 additions and 2 deletions

View File

@ -1,12 +1,16 @@
import ipaddress import ipaddress
from ipaddress import IPv4Interface from ipaddress import IPv4Address, IPv4Interface
from typing import List, Optional, Sequence, Tuple from typing import List, Optional, Sequence, Tuple
from netifaces import AF_INET, ifaddresses, interfaces from netifaces import AF_INET, ifaddresses, interfaces
def get_my_ip_addresses_legacy() -> Sequence[str]: def get_my_ip_addresses_legacy() -> Sequence[str]:
return [str(interface.ip) for interface in get_network_interfaces()] return [str(ip) for ip in get_my_ip_addresses()]
def get_my_ip_addresses() -> Sequence[IPv4Address]:
return [interface.ip for interface in get_network_interfaces()]
def get_network_interfaces() -> List[IPv4Interface]: def get_network_interfaces() -> List[IPv4Interface]: