From 0e285428dfadebebb27b0ee6a7851d6622b7f341 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 31 Jan 2018 07:24:49 +0100 Subject: mpm: net: Add get_local_ip_addrs() method --- mpm/python/usrp_mpm/sys_utils/net.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'mpm/python') diff --git a/mpm/python/usrp_mpm/sys_utils/net.py b/mpm/python/usrp_mpm/sys_utils/net.py index 2cf4071ab..f40e147dc 100644 --- a/mpm/python/usrp_mpm/sys_utils/net.py +++ b/mpm/python/usrp_mpm/sys_utils/net.py @@ -9,7 +9,7 @@ N310 implementation module import itertools import socket from six import iteritems -from pyroute2 import IPRoute +from pyroute2 import IPRoute, IPDB from usrp_mpm.mpmlog import get_logger @@ -117,3 +117,17 @@ def get_mac_addr(remote_addr): if not addrs: return None return addrs[0].get_attr('NDA_LLADDR') + +def get_local_ip_addrs(ipv4_only=False): + """ + Return a set of IP addresses which are bound to local interfaces. + """ + with IPDB() as ipdb: + return { + ip_subnet[0] + for ip_subnet_list + in [x['ipaddr'] for x in ipdb.interfaces.values()] + for ip_subnet in ip_subnet_list + if not ipv4_only or ip_subnet[0].find(':') == -1 + } + -- cgit v1.2.3