#!/usr/bin/env python3 import glob import os from enum import Enum class IFaceType(Enum): ETHERNET = "\U000f0200" WIRELESS = "\U000f05a9" TUNNEL = "\U000f0582" UNKNOWN = "" @staticmethod def from_path(path: str): try: with open(os.path.join(path, "type"), "r") as f: match int(f.readline()): case 1 if os.path.isdir( os.path.join(path, "wireless") ) or os.path.islink(os.path.join(path, "phy80211")): return IFaceType.WIRELESS case 1: return IFaceType.ETHERNET case 65534: return IFaceType.TUNNEL case _: raise ValueError("Invalid interface type") except Exception: return IFaceType.UNKNOWN class IFace: def __init__(self, path: str): self.path = path self.name = os.path.basename(path) self._type = IFaceType.from_path(path) def __str__(self): return self._type.value def main(): ifaces = [] for net in glob.glob("/sys/class/net/*"): iface = IFace(net) if iface.name != "lo" and iface._type != IFaceType.UNKNOWN: ifaces.append(str(iface)) print(f" {" ".join(ifaces)} \n") if __name__ == "__main__": main()