# HG changeset patch # User k0s # Date 1266423445 0 # Node ID 0c11c8102fba40c78ead7528509311153468d0a4 # Parent c69fb6d00ece2173ed923e9dd8133addc9b4df33 more robust way of getting interfaces diff -r c69fb6d00ece -r 0c11c8102fba silvermirror/utils.py --- a/silvermirror/utils.py Tue Feb 16 21:25:25 2010 +0000 +++ b/silvermirror/utils.py Wed Feb 17 16:17:25 2010 +0000 @@ -9,9 +9,17 @@ def ip_addresses(): """dictionary of ip4 addresses for the machine""" + interfaces = [] + for i in netifaces.interfaces(): + try: + value = netifaces.ifaddresses(i).get(2) + if value: + interfaces.append(i) + except ValueError: + continue + return dict([(i, netifaces.ifaddresses(i)[2][0]['addr']) - for i in netifaces.interfaces() - if netifaces.ifaddresses(i).get(2) + for i in interfaces ]) if __name__ == '__main__':