diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-01-31 07:24:49 +0100 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-02-07 13:44:54 -0800 |
commit | 0e285428dfadebebb27b0ee6a7851d6622b7f341 (patch) | |
tree | ecbde4773494f8433ceaacd8642fb64af74f5d53 /mpm/python/usrp_mpm | |
parent | c2747ed0ce2488bacc9b6fab6ac9f5f47e9a5eef (diff) | |
download | uhd-0e285428dfadebebb27b0ee6a7851d6622b7f341.tar.gz uhd-0e285428dfadebebb27b0ee6a7851d6622b7f341.tar.bz2 uhd-0e285428dfadebebb27b0ee6a7851d6622b7f341.zip |
mpm: net: Add get_local_ip_addrs() method
Diffstat (limited to 'mpm/python/usrp_mpm')
-rw-r--r-- | mpm/python/usrp_mpm/sys_utils/net.py | 16 |
1 files changed, 15 insertions, 1 deletions
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 + } + |