Ejemplo n.º 1
0
def getIpAddresses():
    "Return a list of the host's IPv4 addresses"
    return [
        addr['address']
        for addr in nl_addr.iter_addrs()
        if addr['family'] == 'inet'
    ]
Ejemplo n.º 2
0
 def addresses(device=None, family=None):
     addrs = nl_addr.iter_addrs()
     filtered = IPAddress._filter_addresses(addrs, device, family)
     for address in filtered:
         yield IPAddressData(address=address['address'],
                             device=address['label'],
                             flags=address['flags'],
                             scope=address['scope'])
Ejemplo n.º 3
0
 def addresses(device=None, family=None):
     addrs = nl_addr.iter_addrs()
     filtered = IPAddress._filter_addresses(addrs, device, family)
     for address in filtered:
         yield IPAddressData(address=address['address'],
                             device=address['label'],
                             flags=address['flags'],
                             scope=address['scope'])
Ejemplo n.º 4
0
 def testGetDeviceByIP(self):
     for addr in nl_addr.iter_addrs():
         # Link-local IPv6 addresses are generated from the MAC address,
         # which is shared between a nic and its bridge. Since We don't
         # support having the same IP address on two different NICs, and
         # link-local IPv6 addresses aren't interesting for 'getDeviceByIP'
         # then ignore them in the test
         if addr['scope'] != 'link':
             self.assertEqual(
                 addr['label'],
                 addresses.getDeviceByIP(addr['address'].split('/')[0]))
Ejemplo n.º 5
0
def getDeviceByIP(ip):
    """
    Get network device by IP address
    :param ip: String representing IPv4 or IPv6
    """
    for addr in nl_addr.iter_addrs():
        address = addr['address'].split('/')[0]
        if (addr['family'] == 'inet' and ip in (address, IPv4toMapped(address))
            ) or (addr['family'] == 'inet6' and ip == address):
            return addr['label']
    return ''
Ejemplo n.º 6
0
def getDeviceByIP(ip):
    """
    Get network device by IP address
    :param ip: String representing IPv4 or IPv6
    """
    for addr in nl_addr.iter_addrs():
        address = addr['address'].split('/')[0]
        if ((addr['family'] == 'inet' and
             ip in (address, IPv4toMapped(address))) or (
                addr['family'] == 'inet6' and ip == address)):
            return addr['label']
    return ''
Ejemplo n.º 7
0
def getIpAddrs():
    addrs = defaultdict(list)
    for addr in nl_addr.iter_addrs():
        addrs[addr['label']].append(addr)
    return addrs
Ejemplo n.º 8
0
def getIpAddrs():
    addrs = defaultdict(list)
    for addr in nl_addr.iter_addrs():
        addrs[addr['label']].append(addr)
    return addrs
Ejemplo n.º 9
0
def getIpAddresses():
    "Return a list of the host's IPv4 addresses"
    return [addr['address'] for addr in nl_addr.iter_addrs() if
            addr['family'] == 'inet']