diff options
author | PMR <pmr@pmr-lander> | 2019-11-05 14:40:59 +0000 |
---|---|---|
committer | PMR <pmr@pmr-lander> | 2019-11-05 14:40:59 +0000 |
commit | 93393f1e53d95e58deae0eda4bdbc08e2884a22b (patch) | |
tree | d80353a13943157fd7d55e5399a3e8e77498722d | |
parent | 6924462a362fd91cd0fb547d52ad411424b08613 (diff) | |
parent | 148b919948d25df67157854ab4d82e8f9f54babc (diff) |
Merge #374923 from ~bladernr/plainbox-provider-checkbox:lp1850652
bin/network_device_info.py: fix traceback when IPv4 is not set on an interface.
-rwxr-xr-x | bin/network_device_info.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/bin/network_device_info.py b/bin/network_device_info.py index 4a827def..925b3f5e 100755 --- a/bin/network_device_info.py +++ b/bin/network_device_info.py @@ -49,11 +49,18 @@ class Utils(): @staticmethod def get_ipv4_address(interface): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl( - s.fileno(), - 0x8915, # SIOCGIFADDR - struct.pack('256s', interface[:15].encode()) - )[20:24]) + try: + ipv4_addr = socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, # SIOCGIFADDR + struct.pack('256s', interface[:15].encode()) + )[20:24]) + except Exception as e: + print("ERROR: getting the IPv4 address for %s: %s" % + (interface, repr(e))) + ipv4_addr = "***NOT CONFIGURED***" + finally: + return ipv4_addr @staticmethod def get_ipv6_address(interface): |