| 1071 | |
| 1072 | # TODO: consolidate the parsing logic between IfconfigOther and netstat |
| 1073 | def get(self, arg): # type: (str) -> Optional[str] |
| 1074 | # NOTE: netstat and ifconfig pull from the same kernel source and |
| 1075 | # therefore have the same output format on the same platform. |
| 1076 | command_output = _popen("netstat", "-iae") |
| 1077 | if not command_output: |
| 1078 | log.warning("no netstat output, marking unusable") |
| 1079 | self.unusable = True |
| 1080 | return None |
| 1081 | |
| 1082 | if self._working_regex: |
| 1083 | # Use regex that worked previously. This can still return None in |
| 1084 | # the case of interface not existing, but at least it's a bit faster. |
| 1085 | return _search(arg + self._working_regex, command_output, flags=re.DOTALL) |
| 1086 | |
| 1087 | # See if either regex matches |
| 1088 | for regex in self._regexes: |
| 1089 | result = _search(arg + regex, command_output, flags=re.DOTALL) |
| 1090 | if result: |
| 1091 | self._working_regex = regex |
| 1092 | return result |
| 1093 | |
| 1094 | return None |
| 1095 | |
| 1096 | |
| 1097 | # TODO: Add to IpLinkIface |