Ejemplo n.º 1
0
    def show(self, print_result=True, hidden=False, **kwargs):
        # type: (bool, bool, **Any) -> Optional[str]
        """
        Print list of available network interfaces in human readable form

        :param print_result: print the results if True, else return it
        :param hidden: if True, also displays invalid interfaces
        """
        res = defaultdict(list)
        for iface_name in sorted(self.data):
            dev = self.data[iface_name]
            if not hidden and not dev.is_valid():
                continue
            prov = dev.provider
            res[prov].append((prov.name, ) + prov._format(dev, **kwargs))
        output = ""
        for provider in res:
            output += pretty_list(res[provider],
                                  [("Source", ) + provider.headers],
                                  sortBy=provider.header_sort) + "\n"
        output = output[:-1]
        if print_result:
            print(output)
            return None
        else:
            return output
Ejemplo n.º 2
0
    def __repr__(self):
        rtlst = []

        for net, msk, gw, iface, cset, metric in self.routes:
            rtlst.append(('%s/%i' % (net, msk), gw, (iface if isinstance(iface, six.string_types) else iface.name), ", ".join(cset) if len(cset) > 0 else "", str(metric)))  # noqa: E501

        return pretty_list(rtlst,
                           [('Destination', 'Next Hop', "Iface", "Src candidates", "Metric")],  # noqa: E501
                           sortBy=1)
Ejemplo n.º 3
0
    def __repr__(self):
        rtlst = []
        for net, msk, gw, iface, addr, metric in self.routes:
            if_repr = resolve_iface(iface).description
            rtlst.append(
                (ltoa(net), ltoa(msk), gw, if_repr, addr, str(metric)))

        return pretty_list(rtlst, [
            ("Network", "Netmask", "Gateway", "Iface", "Output IP", "Metric")
        ])  # noqa: E501
Ejemplo n.º 4
0
    def __repr__(self):
        rtlst = []
        for net, msk, gw, iface, addr, metric in self.routes:
            rtlst.append(
                (ltoa(net), ltoa(msk), gw,
                 (iface.name if not isinstance(iface, six.string_types) else
                  iface), addr, str(metric)))

        return pretty_list(rtlst, [
            ("Network", "Netmask", "Gateway", "Iface", "Output IP", "Metric")
        ])
Ejemplo n.º 5
0
    def __repr__(self):
        # type: () -> str
        rtlst = []  # type: List[Tuple[Union[str, List[str]], ...]]
        for net, msk, gw, iface, addr, metric in self.routes:
            if_repr = cast(str, resolve_iface(iface).description)
            rtlst.append(
                (ltoa(net), ltoa(msk), gw, if_repr, addr, str(metric)))

        return pretty_list(rtlst, [
            ("Network", "Netmask", "Gateway", "Iface", "Output IP", "Metric")
        ])  # noqa: E501
Ejemplo n.º 6
0
    def __repr__(self):
        rtlst = []
        for net, msk, gw, iface, addr, metric in self.routes:
            rtlst.append((ltoa(net),
                          ltoa(msk),
                          gw,
                          (iface.name if not isinstance(iface, six.string_types) else iface),  # noqa: E501
                          addr,
                          str(metric)))

        return pretty_list(rtlst,
                           [("Network", "Netmask", "Gateway", "Iface", "Output IP", "Metric")])  # noqa: E501
Ejemplo n.º 7
0
    def __repr__(self):
        rtlst = []

        for net, msk, gw, iface, cset, metric in self.routes:
            if_repr = resolve_iface(iface).description
            rtlst.append(
                ('%s/%i' % (net, msk), gw, if_repr, cset, str(metric)))

        return pretty_list(
            rtlst,
            [('Destination', 'Next Hop', "Iface", "Src candidates", "Metric")
             ],  # noqa: E501
            sortBy=1)
Ejemplo n.º 8
0
    def __repr__(self):
        rtlst = []

        for net, msk, gw, iface, cset, metric in self.routes:
            rtlst.append(
                ('%s/%i' % (net, msk), gw, (iface if isinstance(
                    iface, six.string_types) else iface.description),
                 ", ".join(cset) if len(cset) > 0 else "", str(metric)))

        return pretty_list(
            rtlst,
            [('Destination', 'Next Hop', "Iface", "Src candidates", "Metric")
             ],  # noqa: E501
            sortBy=1)
Ejemplo n.º 9
0
    def show(self, resolve_mac=True, print_result=True):
        """Print list of available network interfaces in human readable form"""
        res = []
        for iface_name in sorted(self.data):
            dev = self.data[iface_name]
            mac = dev.mac
            if resolve_mac and conf.manufdb:
                mac = conf.manufdb._resolve_MAC(mac)
            res.append((str(dev.win_index), str(dev.name), str(dev.ip), mac))

        res = pretty_list(res, [("INDEX", "IFACE", "IP", "MAC")])
        if print_result:
            print(res)
        else:
            return res
Ejemplo n.º 10
0
    def __repr__(self):
        # type: () -> str
        rtlst = []  # type: List[Tuple[Union[str, List[str]], ...]]

        for net, msk, gw, iface, cset, metric in self.routes:
            if_repr = cast(str, resolve_iface(iface).description)
            rtlst.append(('%s/%i' % (net, msk),
                          gw,
                          if_repr,
                          cset,
                          str(metric)))

        return pretty_list(rtlst,
                           [('Destination', 'Next Hop', "Iface", "Src candidates", "Metric")],  # noqa: E501
                           sortBy=1)
Ejemplo n.º 11
0
    def show(self, resolve_mac=True, print_result=True):
        """Print list of available network interfaces in human readable form"""
        res = []
        for iface_name in sorted(self.data):
            dev = self.data[iface_name]
            mac = dev.mac
            if resolve_mac and conf.manufdb:
                mac = conf.manufdb._resolve_MAC(mac)
            res.append((str(dev.win_index).ljust(5), str(dev.name).ljust(35), str(dev.ip).ljust(15), mac))

        res = pretty_list(res, [("INDEX", "IFACE", "IP", "MAC")])
        if print_result:
            print(res)
        else:
            return res
Ejemplo n.º 12
0
    def show(self, resolve_mac=True, print_result=True):
        """Print list of available network interfaces in human readable form"""
        res = []
        for iface_name in sorted(self.data):
            dev = self.data[iface_name]
            mac = dev.mac
            if resolve_mac and conf.manufdb:
                mac = conf.manufdb._resolve_MAC(mac)
            validity_color = lambda x: conf.color_theme.red if x else \
                conf.color_theme.green
            description = validity_color(dev.is_invalid())(str(
                dev.description))
            index = str(dev.win_index)
            res.append((index, description, str(dev.ip), mac))

        res = pretty_list(res, [("INDEX", "IFACE", "IP", "MAC")], sortBy=2)
        if print_result:
            print(res)
        else:
            return res