From eb48c9eba49fa3343c2b3e8c519326ee16d02e9d Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 28 Apr 2010 07:14:33 +0000 Subject: [PATCH] cleaned up and tested again --- sioc.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/sioc.py b/sioc.py index 489a93e..b4e0b46 100644 --- a/sioc.py +++ b/sioc.py @@ -39,20 +39,13 @@ def gifconf(): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) (stdout, stderr) = ip.communicate() - ip.wait() + # no wait is needed when using communicate for line in stdout.split("\n"): - 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 = [ field.strip() for field in line.split() ] + if fields and fields[0] == "inet": # fields[-1] is the last column in fields, which has the interface name - # fields[1] has the IP address + # fields[1] has the IP address / netmask width ret[fields[-1]] = fields[1].split("/")[0] - return ret def gifhwaddr(interface): -- 2.43.0