Use ip instead of deprecated ifconfig.

Signed-off-by: Max <max.suraev@fairwaves.co>
This commit is contained in:
Max
2015-03-27 12:21:56 +01:00
parent f274d9da1c
commit 171e9b83da

View File

@@ -137,25 +137,14 @@ def is_valid_fw_image(fw_image):
######################################################################## ########################################################################
# interface discovery and device enumeration # interface discovery and device enumeration
######################################################################## ########################################################################
def command(*args):
p = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
ret = p.wait()
verbose = p.stdout.read().decode()
if ret != 0: raise Exception(verbose)
return verbose
def get_interfaces(): def get_interfaces():
if(platform.system() is "Windows"): return win_get_interfaces() if(platform.system() is "Windows"): return win_get_interfaces()
else: return unix_get_interfaces() else: return unix_get_interfaces()
def unix_get_interfaces(): def unix_get_interfaces():
ifconfig = command("/sbin/ifconfig") ipint = subprocess.check_output(["/sbin/ip", "-4", "a", "s", "up"])
ip_addr_re = "cast\D*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})" ip_addr_re = "brd\D*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
bcasts = re.findall(ip_addr_re, ifconfig) bcasts = re.findall(ip_addr_re, ipint)
return bcasts return bcasts
def win_get_interfaces(): def win_get_interfaces():