def get_interfaces(wifi=True, ethernet=True):
try:
output = subprocess.run(['nmcli', '--mode', 'tabular', '--terse', '--fields', 'TYPE,DEVICE', 'device', 'status'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output.check_returncode()
lines = output.stdout.decode('utf-8').split('\n')
interfaces = []
for line in lines:
if line:
elements = line.strip().split(':')
if (wifi and elements[0] == 'wifi') or (ethernet and elements[0] == 'ethernet'):
interfaces.append(elements[1])
return interfaces
except subprocess.CalledProcessError:
error = utils.format_std_string(output.stderr)
logger.error(error)
return False
except Exception as ex:
logger.error(ex)
return False
评论列表
文章目录