- ip = subprocess.Popen(["/sbin/ip", "-4", "addr", "ls"],
+ ip = subprocess.Popen(["/sbin/ip", "-4", "addr", "show"],
- stderr=subprocess.PIPE, close_fds=True)
+ stderr=subprocess.PIPE, close_fds=True,
+ universal_newlines=True)
(stdout, stderr) = ip.communicate()
# no wait is needed when using communicate
for line in stdout.split("\n"):
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
(stdout, stderr) = ip.communicate()
# no wait is needed when using communicate
for line in stdout.split("\n"):
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