- if line.startswith(" inet "):
- fields = line.split(" ")
- ret[fields[-1]] = fields[5].split("/")[0]
+ 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 / netmask width
+ ret[fields[-1]] = fields[1].split("/")[0]