ipaddons

ipaddons.ip_allocation(supernet: UnSpecNet, used_networks: UnspecNetSeq | None = None, ignore_invalid_subnets: bool = True) IPv4Allocation | IPv6Allocation

Create an IP allocation.

Creates and returns an IP allocation object.

Parameters:
  • supernet – An IPv4 or IPv6 network, either as a string or as an ipaddress network object.

  • used_networks – A list of subnets of the supernet that are already in use in this allocation, either as a string or an ipaddress network object.

  • ignore_invalid_subnets – If set to False, used subnets that do not overlap with the supernet will raise a ValueError.

Returns:

An IPv4Allocation or IPv6Allocation instance, depending on the passed supernet argument. Same principle as ipaddress.ip_network().

class ipaddons.IPv4Allocation(supernet: UnSpecNet, used_subnets: UnspecNetSeq | None = None, ignore_invalid_subnets: bool = True)

An IP allocation.

The object represents a supernet (the allocation) with an optional list of used (assigned) subnets. You can also request an iterator for free subnets of a specific size.

Parameters:
  • supernet – An IPv4 or IPv6 network, either as a string or as an ipaddress network object.

  • used_subnets – A list of subnets of the supernet that are already in use in this allocation, either as string or an ipaddress network object.

  • ignore_invalid_subnets – If set to False, used subnets that do not overlap with the supernet will raise a ValueError.

add_used_subnets(subnets: UnspecNetSeq) None

Add additional subnets to the list of used networks in this allocation.

Parameters:

subnets – A list of networks that are added to the in-use networks of this allocation, either as a string or ipaddress network objects.

get_free_subnets(prefixlen: int) Generator[_N, None, None]

List free subnets of a specific size.

Parameters:

prefixlen – Size of the free subnets returned in CIDR notation.

Returns:

An iterator for free subnets of prefixlen size.

set_used_subnets(subnets: UnspecNetSeq) None

Set list of used networks in this allocation.

Parameters:

subnets – A list of networks that are set as in-used, either as a string or ipaddress network objects.

property used_subnets: Generator[_N, None, None]

Used subnets in this allocation.

Getter:

An iterator for used networks in this allocation.

Setter:

Sets the list of used networks.

Type:

List of networks either as string or ipaddress network objects.

class ipaddons.IPv6Allocation(supernet: UnSpecNet, used_subnets: UnspecNetSeq | None = None, ignore_invalid_subnets: bool = True)

An IP allocation.

The object represents a supernet (the allocation) with an optional list of used (assigned) subnets. You can also request an iterator for free subnets of a specific size.

Parameters:
  • supernet – An IPv4 or IPv6 network, either as a string or as an ipaddress network object.

  • used_subnets – A list of subnets of the supernet that are already in use in this allocation, either as string or an ipaddress network object.

  • ignore_invalid_subnets – If set to False, used subnets that do not overlap with the supernet will raise a ValueError.

add_used_subnets(subnets: UnspecNetSeq) None

Add additional subnets to the list of used networks in this allocation.

Parameters:

subnets – A list of networks that are added to the in-use networks of this allocation, either as a string or ipaddress network objects.

get_free_subnets(prefixlen: int) Generator[_N, None, None]

List free subnets of a specific size.

Parameters:

prefixlen – Size of the free subnets returned in CIDR notation.

Returns:

An iterator for free subnets of prefixlen size.

set_used_subnets(subnets: UnspecNetSeq) None

Set list of used networks in this allocation.

Parameters:

subnets – A list of networks that are set as in-used, either as a string or ipaddress network objects.

property used_subnets: Generator[_N, None, None]

Used subnets in this allocation.

Getter:

An iterator for used networks in this allocation.

Setter:

Sets the list of used networks.

Type:

List of networks either as string or ipaddress network objects.