| 1003 | return check_command("ifconfig") |
| 1004 | |
| 1005 | def get(self, arg): # type: (str) -> Optional[str] |
| 1006 | if not arg: |
| 1007 | return None |
| 1008 | |
| 1009 | # Cache output from testing command so first call isn't wasted |
| 1010 | command_output = "" |
| 1011 | |
| 1012 | # Test which arguments are valid to the command |
| 1013 | if not self._args_tested: |
| 1014 | for pair_to_test in self._args: |
| 1015 | try: |
| 1016 | command_output = _popen("ifconfig", pair_to_test[0]) |
| 1017 | self._good_pair = list(pair_to_test) # noqa: T484 |
| 1018 | if isinstance(self._good_pair[1], str): |
| 1019 | self._good_pair[1] += MAC_RE_COLON |
| 1020 | break |
| 1021 | except CalledProcessError as ex: |
| 1022 | if DEBUG: |
| 1023 | log.debug( |
| 1024 | "IfconfigOther pair test failed for (%s, %s): %s", |
| 1025 | pair_to_test[0], |
| 1026 | pair_to_test[1], |
| 1027 | str(ex), |
| 1028 | ) |
| 1029 | |
| 1030 | if not self._good_pair: |
| 1031 | self.unusable = True |
| 1032 | return None |
| 1033 | |
| 1034 | self._args_tested = True |
| 1035 | |
| 1036 | if not command_output and isinstance(self._good_pair[0], str): |
| 1037 | command_output = _popen("ifconfig", self._good_pair[0]) |
| 1038 | |
| 1039 | # Handle the two possible search terms |
| 1040 | if isinstance(self._good_pair[1], tuple): |
| 1041 | for term in self._good_pair[1]: |
| 1042 | regex = term + MAC_RE_COLON |
| 1043 | result = _search(re.escape(arg) + regex, command_output) |
| 1044 | |
| 1045 | if result: |
| 1046 | # changes type from tuple to str, so the else statement |
| 1047 | # will be hit on the next call to this method |
| 1048 | self._good_pair[1] = regex |
| 1049 | return result |
| 1050 | return None |
| 1051 | else: |
| 1052 | return _search(re.escape(arg) + self._good_pair[1], command_output) |
| 1053 | |
| 1054 | |
| 1055 | class NetstatIface(Method): |