| 1119 | return check_command("ip") |
| 1120 | |
| 1121 | def get(self, arg): # type: (str) -> Optional[str] |
| 1122 | # Check if this version of "ip link" accepts an interface argument |
| 1123 | # Not accepting one is a quirk of older versions of 'iproute2' |
| 1124 | # TODO: is it "ip link <arg>" on some platforms and "ip link show <arg>" on others? |
| 1125 | command_output = "" |
| 1126 | |
| 1127 | if not self._tested_arg: |
| 1128 | try: |
| 1129 | command_output = _popen("ip", "link show " + arg) |
| 1130 | self._iface_arg = True |
| 1131 | except CalledProcessError as err: |
| 1132 | # Output: 'Command "eth0" is unknown, try "ip link help"' |
| 1133 | if err.returncode != 255: |
| 1134 | raise err |
| 1135 | self._tested_arg = True |
| 1136 | |
| 1137 | if self._iface_arg: |
| 1138 | if not command_output: # Don't repeat work on first run |
| 1139 | command_output = _popen("ip", "link show " + arg) |
| 1140 | return _search(arg + self._regex, command_output) |
| 1141 | else: |
| 1142 | # TODO: improve this regex to not need extra portion for no arg |
| 1143 | command_output = _popen("ip", "link") |
| 1144 | return _search(arg + r":" + self._regex, command_output) |
| 1145 | |
| 1146 | |
| 1147 | class DefaultIfaceLinuxRouteFile(Method): |