예제 #1
0
    def _get_ifindex_ipv4_mac_mappings(self, column='ipNetToMediaPhysAddress'):
        """Get IP/MAC mappings from a table indexed by IfIndex+IpAddress."""
        ipv4_phys_addrs = yield self.retrieve_column(column)

        mappings = set()
        ignore_count = 0

        for row_index, phys_address in ipv4_phys_addrs.items():
            ifindex = row_index[0]
            ip_address = row_index[1:]
            if len(ip_address) != 4:
                ignore_count += 1
                continue

            ip = oid_to_ipv4(ip_address)
            mac = self._binary_mac_to_hex(phys_address)

            row = (ifindex, ip, mac)
            mappings.add(row)

        if ignore_count:
            self._logger.warning(
                "ignored %d/%d invalid IPv4 addresses from %s", ignore_count,
                len(ipv4_phys_addrs), column)
        self._logger.debug("ip/mac pairs: Got %d rows from %s",
                           len(ipv4_phys_addrs), column)
        returnValue(mappings)
예제 #2
0
파일: ip_mib.py 프로젝트: Uninett/nav
    def _get_interface_ipv4_addresses(self,
                                      ifindex_column='ipAdEntIfIndex',
                                      netmask_column='ipAdEntNetMask'):
        """Get IPv4 address information for interfaces from a table
        indexed by IpAddress.  Default is the ipAddrTable.

        """
        address_rows = yield self.retrieve_columns(
            (ifindex_column, netmask_column))

        addresses = set()
        ignore_count = 0

        for row_index, row in address_rows.items():
            if len(row_index) != 4:
                ignore_count += 1
                continue

            ip = oid_to_ipv4(row_index)
            ifindex = row[ifindex_column]
            netmask = row[netmask_column]
            try:
                prefix = ip.make_net(netmask)
            except ValueError as err:
                self._logger.warning(
                    "ignoring IP address %s due to invalid netmask %s (%s)",
                    ip,
                    netmask,
                    err,
                )
            else:
                new_row = (ifindex, ip, prefix)
                addresses.add(new_row)

        if ignore_count:
            self._logger.warning(
                "ignored %d/%d invalid IPv4 addresses from %s",
                ignore_count,
                len(address_rows),
                ifindex_column,
            )
        self._logger.debug(
            "interface addresses: Got %d rows from %s",
            len(address_rows),
            ifindex_column,
        )
        returnValue(addresses)
예제 #3
0
 def _bgp_row_to_remote_ip(row_index):
     return oid_to_ipv4(row_index)