From b985b03de06cf5d135e2d63b8d0179816733416d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=92=90?= Date: Wed, 28 Feb 2024 13:54:24 +0800 Subject: [PATCH] Add ethtool command to __get_devices_info function --- category/get_net_info.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/category/get_net_info.py b/category/get_net_info.py index 48cdbb0..0322b3d 100644 --- a/category/get_net_info.py +++ b/category/get_net_info.py @@ -70,10 +70,11 @@ class NetInfo: def __get_devices_info(self): ''' - nmcli con show + nmcli con show and ethtool ''' cmd_name = "nmcli con show" res_list = [] + res_e = [] res = '' devices_command="nmcli con show" @@ -85,8 +86,17 @@ class NetInfo: if type in ['bridge', 'ethernet']: cmd_result = Command.cmd_run('ethtool -i ' + device) res_list.append(cmd_result) - + + cmd_result = Command.cmd_run('ethtool ' + device) + for sent in reversed(cmd_result.split('\n')): + if 'Link detected' in sent: + status = sent.split(':',1)[1].strip() + self.__link_status[device] = status + break + res_e.append(cmd_result) + #wrap result + res_list += res_e for i,cmd_result in enumerate(res_list): split = '=' if i == len(res_list)-1 else '-' res += FileOperation.wrap_output_format(cmd_name, cmd_result, split) -- Gitee