From edc6810d81e11e6d2759c4306595e16e0a695de3 Mon Sep 17 00:00:00 2001 From: Jeff Lane Date: Wed, 30 Oct 2019 11:24:29 -0400 Subject: Fix bug that causes traceback in bin/network_device_info.py when ipv4 is not configured for an interface. LP: #1850652 --- bin/network_device_info.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/network_device_info.py b/bin/network_device_info.py index 4a827de..1874772 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): @@ -362,6 +369,7 @@ if __name__ == "__main__": # Report udev detected devices first print("[ Devices found by udev ]".center(80, '-')) + print("DEBUG: %s" % udev.devices()) for device in udev.devices(): print(device) -- cgit v1.2.3