How to use the netaddr.iter_iprange function in netaddr

To help you get started, we’ve selected a few netaddr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drkjam / netaddr / test / ip / test_ip_ranges.py View on Github external
def test_iprange_boundaries():
    assert list(iter_iprange('192.0.2.0', '192.0.2.7')) == [
        IPAddress('192.0.2.0'),
        IPAddress('192.0.2.1'),
        IPAddress('192.0.2.2'),
        IPAddress('192.0.2.3'),
        IPAddress('192.0.2.4'),
        IPAddress('192.0.2.5'),
        IPAddress('192.0.2.6'),
        IPAddress('192.0.2.7'),
    ]

    assert list(iter_iprange('::ffff:192.0.2.0', '::ffff:192.0.2.7')) == [
        IPAddress('::ffff:192.0.2.0'),
        IPAddress('::ffff:192.0.2.1'),
        IPAddress('::ffff:192.0.2.2'),
        IPAddress('::ffff:192.0.2.3'),
        IPAddress('::ffff:192.0.2.4'),
        IPAddress('::ffff:192.0.2.5'),
        IPAddress('::ffff:192.0.2.6'),
        IPAddress('::ffff:192.0.2.7'),
    ]
github F5Networks / f5-openstack-agent / test / functional / neutronless / testlib / fake_rpc.py View on Github external
def _init_subnet_addr_generator(self, subnet_id, subnet):
        def ip_generator(ip_list):
            for ip in ip_list:
                yield ip

        if not subnet:
            self._subnets[subnet_id] = ip_generator([])

        allocation_pools = subnet.get('allocation_pools', None)
        for pool in allocation_pools:
            start = pool['start']
            end = pool['end']
            ip_list = list(str(ip) for ip in
                           netaddr.iter_iprange(start, end))

        self._subnets[subnet_id] = ip_generator(
            [ip for ip in ip_list])
github gojhonny / Pentesting-Scripts / goexpand.py View on Github external
def expand_range(iprange, outfile):
    print "{}[*]{} Expanding {}-{}".format(colors.blue, colors.normal, iprange[0], iprange[1])
    if iprange[0] < iprange[1]:
        results = iter_iprange(iprange[0], iprange[1])
    else:
        results = iter_iprange(iprange[1], iprange[0])
    return results
github apache / cloudstack / test / integration / component / test_shared_networks.py View on Github external
self.api_client,
                            id=self.project1_admin_account_virtual_machine.id,
                            listall=True
                            )
        self.assertEqual(
            isinstance(vms, list),
            True,
            "listVirtualMachines returned invalid object in response."
            )
        self.assertNotEqual(
            len(vms),
            0,
            "listVirtualMachines returned empty list."
            )

        ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"])))
        if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range:
            self.fail("Virtual machine ip should be from the ip range assigned to network created.")
github apache / cloudstack / test / integration / component / maint / test_multiple_ip_ranges.py View on Github external
mode=self.testdata["mode"],
            )
        except Exception as e:
            raise Exception(
                "Warning: Exception during vm deployment: {}".format(e))
        self.vm_response = VirtualMachine.list(
            self.apiclient,
            id=self.virtual_machine.id
        )
        self.assertEqual(
            isinstance(self.vm_response, list),
            True,
            "Check VM list response returned a valid list"
        )
        self.ip_range = list(
            netaddr.iter_iprange(
                unicode(
                    self.testdata["vlan_ip_range"]["startip"]), unicode(
                    self.testdata["vlan_ip_range"]["endip"])))
        self.nic_ip = netaddr.IPAddress(
            unicode(
                self.vm_response[0].nic[0].ipaddress))
        self.debug("vm got {} as ip address".format(self.nic_ip))
        self.assertIn(
            self.nic_ip,
            self.ip_range,
            "VM did not get the ip address from the new ip range"
        )
        ip_alias = self.dbclient.execute(
            "select ip4_address from nic_ip_alias;"
        )
        self.alias_ip = str(ip_alias[0][0])
github IBM / power-up / scripts / python / allocate_ip_addresses.py View on Github external
def load_network_ips(inventory):
    networks = inventory['networks']
    available_network_ips = {}
    for net_name, net in networks.iteritems():
        if 'available-ips' in net:
            ip_list_raw = net.get('available-ips')
            ip_list_out = []
            for ip in ip_list_raw:
                if ' ' in ip:
                    ip_range = ip.split()
                    for _ip in netaddr.iter_iprange(ip_range[0], ip_range[1]):
                        ip_list_out.append(_ip)
                else:
                    ip_list_out.append(ip)
            available_network_ips[net_name] = ip_list_out

    return available_network_ips
github midnightslacker / threat_intel / ip_gen.py View on Github external
def ipRange():
   ip_list = list(iter_iprange(ip_range.split('-')[0], ip_range.split('-')[1]))
   for ip in ip_list:
       print ('%s' % ip)
github funkandwagnalls / ranger / ranger.py View on Github external
def range_to_list(self):
        ip_list = []
        ip_list = list(netaddr.iter_iprange(self.range_value1, self.range_value2))
        return(ip_list)
github openstack / neutron / neutron / plugins / cisco / db / n1kv_db_v2.py View on Github external
def get_multicast_ip(network_profile):
    """
    Retrieve a multicast ip from the defined pool.

    :params network_profile: object of type network profile
    :returns: string representing multicast IP
    """
    # Round robin multicast ip allocation
    min_ip, max_ip = _get_multicast_ip_range(network_profile)
    addr_list = list((netaddr.iter_iprange(min_ip, max_ip)))
    mul_ip_str = str(addr_list[network_profile.multicast_ip_index])

    network_profile.multicast_ip_index += 1
    if network_profile.multicast_ip_index == len(addr_list):
        network_profile.multicast_ip_index = 0
    return mul_ip_str