diff options
author | Jeff Lane <jeffrey.lane@canonical.com> | 2019-10-30 11:24:29 -0400 |
---|---|---|
committer | Jeff Lane <jeffrey.lane@canonical.com> | 2019-10-30 11:24:29 -0400 |
commit | edc6810d81e11e6d2759c4306595e16e0a695de3 (patch) | |
tree | fa0da3449ccd20511120a076826a9aafc99d58e8 | |
parent | 6924462a362fd91cd0fb547d52ad411424b08613 (diff) |
Fix bug that causes traceback in bin/network_device_info.py when ipv4 is not configured for an interface. LP: #1850652
-rwxr-xr-x | bin/network_device_info.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/bin/network_device_info.py b/bin/network_device_info.py index 4a827def..18747721 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) |