changeset 11:0c11c8102fba

more robust way of getting interfaces
author k0s <k0scist@gmail.com>
date Wed, 17 Feb 2010 16:17:25 +0000
parents c69fb6d00ece
children 5d4706492f9a
files silvermirror/utils.py
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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__':