updated gifconf() function
authorMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 2 Mar 2010 15:23:18 +0000 (15:23 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 2 Mar 2010 15:23:18 +0000 (15:23 +0000)
sioc.py

diff --git a/sioc.py b/sioc.py
index d596f77..489a93e 100644 (file)
--- a/sioc.py
+++ b/sioc.py
@@ -41,9 +41,18 @@ def gifconf():
     (stdout, stderr) = ip.communicate()
     ip.wait()
     for line in stdout.split("\n"):
-        if line.startswith("    inet "):
-            fields = line.split(" ")
-            ret[fields[-1]] = fields[5].split("/")[0]
+        line = line.strip()
+        if line =='':continue
+
+        fields = line.split(" ")
+        # clean up fields
+        for i in range(0,len(fields)): fields[i]=fields[i].strip()
+
+        if fields[0] == "inet":
+            # fields[-1] is the last column in fields, which has the interface name
+            # fields[1] has the IP address
+            ret[fields[-1]] = fields[1].split("/")[0]
+
     return ret
 
 def gifhwaddr(interface):