netaddresstool¶
IPv4 Address Tools¶
Author: Jacek Kotlarski –<szumak@virthost.pl> Created: 23.06.2023
Purpose: Classes for IPv4
- class jsktoolbox.netaddresstool.ipv4.Address(addr)[source]¶
Bases:
IComparators,BClasses,NoDynamicAttributesAddress class for representing IPv4 addresses.
Constructor arguments: addr: Union[str, int, List[Octets]] – IPv4 address representation as string, integer or list of four Octets
Public property: octets: List[Octet] – Return list of four Octets
Public setter: octets: Union[str, int, List] – Set IPv4 address from string, integer or list of octets.
- __init__(addr)[source]¶
Constructor.
### Arguments: * addr: Union[str, int, Union[List[str], List[int], List[Octet]]] - IPv4 address in various formats (string, integer, or list of octets).
- class jsktoolbox.netaddresstool.ipv4.Netmask(addr)[source]¶
Bases:
BClasses,NoDynamicAttributesNetmask class for IPv4 addresses.
Constructor argument: addr: Union[str, int, List] – Set netmask from string, integer or list of proper format of netmask octets.
Public property: octets: List[Octet] – Return netmask as list of four octets. cidr: str – Return netmask in CIDR string format.
Public setter: octets: List[Octet] – Set netmask from list of 4 values [int||str||Octets]. cidr: Union[str, int] – Set netmask from CIDR format of string or integer.
- __init__(addr)[source]¶
Constructor.
### Arguments: * addr: Union[str, int, Union[List[str], List[int], List[Octet]]] - IPv4 netmask in various formats (string, integer, or list of octets).
- property octets: List[Octet]¶
Return octets list of four Octets.
### Returns: List[Octet] - List of four Octet objects representing each byte.
- class jsktoolbox.netaddresstool.ipv4.Network(addr)[source]¶
Bases:
BClasses,NoDynamicAttributesNetwork IPv4 class.
Constructor argument: addr: Union[str, List] – Set IPv4 network address from string or two element list of address [Address,str,int,list] and netmask [Netmask, str, int, list].
Public property: address: Address – Return IPv4 address set in the constructor. broadcast: Address – Return broadcast address. count: int – Return count hosts addresses in network range. hosts(limit: Optional[int] = DEFAULT_IPV4_HOST_LIMIT): List[Address] – Deprecated helper returning host list with an optional safety limit. iter_hosts(limit: Optional[int] = DEFAULT_IPV4_HOST_LIMIT) -> Iterator[Address] – Lazy host iterator respecting optional limits. network: Address – Return network address. mask: Netmask – Return netmask. max: Address – Return max address of host in network range. min: Address – Return min address of host in network range.
- __init__(addr)[source]¶
Constructor.
### Arguments: * addr: Union[str, List] - IPv4 network address in CIDR notation (string) or list format.
- property broadcast: Address¶
Return broadcast address.
### Returns: Address - The broadcast address for this network.
- property count: int¶
Return count hosts addresses in network range.
### Returns: int - Number of host addresses in the network.
- hosts(limit=65536)[source]¶
Return list of hosts in network range. (Deprecated)
### Arguments: * limit: Optional[int] - Maximum number of hosts allowed to materialise. Defaults to DEFAULT_IPV4_HOST_LIMIT.
### Returns: [List[Address]] - List of host addresses within the network.
### Raises: * ValueError: Propagated from iter_hosts() when the number of hosts exceeds the configured limit.
- iter_hosts(limit=65536)[source]¶
Yield hosts in network range lazily.
### Arguments: * limit: Optional[int] - Maximum number of hosts allowed before raising. Defaults to DEFAULT_IPV4_HOST_LIMIT.
### Returns: Iterator[Address] - Generator producing host addresses in ascending order.
### Raises: * ValueError: Raised when the number of hosts exceeds the configured limit.
- property max: Address¶
Return last address of host in network range.
### Returns: Address - The last usable host address.
- __setattr__(name, value)¶
Prevent dynamic attribute assignment on instances.
### Raises: * AttributeError: Attribute not previously declared.
- class jsktoolbox.netaddresstool.ipv4.SubNetwork(network, mask)[source]¶
Bases:
BClasses,NoDynamicAttributesSubNetwork calculator class.
Constructor argument: network: Network – The address of the network where the subnet is being searched for. mask: Netmask – Subnet mask.
Public property: subnets(limit: Optional[int] = DEFAULT_IPV4_SUBNET_LIMIT): List[Network] – Deprecated helper returning subnet list with an optional safety limit. iter_subnets(limit: Optional[int] = DEFAULT_IPV4_SUBNET_LIMIT) -> Iterator[Network] – Lazy subnet iterator.
- __setattr__(name, value)¶
Prevent dynamic attribute assignment on instances.
### Raises: * AttributeError: Attribute not previously declared.
- __init__(network, mask)[source]¶
Constructor.
### Arguments: * network: Network - Network address object. * mask: Netmask - Netmask object defining the subnet size.
- subnets(limit=4096)[source]¶
Return subnets list. (Deprecated)
### Arguments: * limit: Optional[int] - Maximum number of subnets to generate. Defaults to DEFAULT_IPV4_SUBNET_LIMIT.
### Returns: [List[Network]] - List of generated subnetworks.
### Raises: * ValueError: Propagated from iter_subnets() when the number of subnets exceeds the configured limit.
- iter_subnets(limit=4096)[source]¶
Yield IPv4 subnetworks lazily.
### Arguments: * limit: Optional[int] - Maximum number of subnetworks allowed before raising. Defaults to DEFAULT_IPV4_SUBNET_LIMIT.
### Returns: Iterator[Network] - Generator producing IPv4 subnetworks in ascending order.
### Raises: * ValueError: Raised when the number of subnetworks exceeds the configured limit.
IPv6 Address Tools¶
Author: Jacek ‘Szumak’ Kotlarski –<szumak@virthost.pl> Created: 14.09.2023
Purpose: Classes for IPv6
https://www.ibm.com/docs/en/ts3500-tape-library?topic=formats-subnet-masks-ipv4-prefixes-ipv6
- class jsktoolbox.netaddresstool.ipv6.Address6(addr)[source]¶
Bases:
IComparators,BClasses,NoDynamicAttributesAddress6 class for representing IPv6 addresses.
Constructor arguments: addr: Union[str, int, List[Word16]] – IPv6 address representation as string, integer or list of eight Word16
Public property: words: List[Word16] – Return list of eight Word16
Public setter: words: Union[str, int, List] – Set IPv6 address from string, integer or list of Word16.
- __init__(addr)[source]¶
Constructor.
### Arguments: * addr: Union[str, int, Union[List[int], List[str], List[Word16]]] - IPv6 address in various formats (string, integer, or list of 16-bit words).
- class jsktoolbox.netaddresstool.ipv6.Prefix6(prefix)[source]¶
Bases:
IComparators,BClasses,NoDynamicAttributesPrefix6 class for IPv6 addresses.
Constructor argument: prefix: Union[str, int] – Set prefix from string or integer.
Public property: prefix: str – Return prefix as string.
Public setter: prefix: Union[str, int] – Set prefix from string or integer.
- __init__(prefix)[source]¶
Constructor.
### Arguments: * prefix: Union[str, int] - IPv6 prefix length (0-128) as string or integer.
- class jsktoolbox.netaddresstool.ipv6.Network6(addr)[source]¶
Bases:
BClasses,NoDynamicAttributesNetwork6 IPv6 class.
Constructor argument: addr: Union[str, List] – Set IPv6 network address from string or two element list of address [Address6,str,int,list] and prefix [Prefix6, str, int].
Public property: address: Address6 – Return IPv6 address set in the constructor. count: int – Return count hosts addresses in network range. hosts(limit: Optional[int] = DEFAULT_IPV6_HOST_LIMIT): List[Address6] – Deprecated helper returning host list with an optional safety limit. iter_hosts(limit: Optional[int] = DEFAULT_IPV6_HOST_LIMIT) -> Iterator[Address6] – Lazy host iterator respecting optional limits. network: Address6 – Return network address. prefix: Prefix6 – Return prefix. max: Address6 – Return max address of host in network range. min: Address6 – Return min address of host in network range.
- __init__(addr)[source]¶
Constructor.
### Arguments: * addr: Union[str, List] - IPv6 network address in CIDR notation (string) or list format.
- property count: int¶
Return number of hosts in subnet.
### Returns: int - Number of addresses in the subnet.
- hosts(limit=65536)[source]¶
Return list of hosts addresses. (Deprecated)
### Arguments: * limit: Optional[int] - Maximum number of hosts allowed to materialise. Defaults to DEFAULT_IPV6_HOST_LIMIT.
### Returns: [List[Address6]] - Host addresses contained within the subnet.
### Raises: * ValueError: Propagated from iter_hosts() when the host count exceeds the configured limit.
- iter_hosts(limit=65536)[source]¶
Yield IPv6 host addresses lazily.
### Arguments: * limit: Optional[int] - Maximum number of hosts allowed before raising. Defaults to DEFAULT_IPV6_HOST_LIMIT.
### Returns: Iterator[Address6] - Generator producing host addresses in ascending order.
### Raises: * ValueError: Raised when the host count exceeds the configured limit.
- property max: Address6¶
Return last IPv6 address from subnet.
### Returns: Address6 - The last address in the subnet.
- property min: Address6¶
Return first IPv6 address from subnet.
### Returns: Address6 - The first address in the subnet.
- class jsktoolbox.netaddresstool.ipv6.SubNetwork6(network, prefix)[source]¶
Bases:
BClasses,NoDynamicAttributesSubNetwork6 calculator class.
Constructor argument: network: Network6 – The address of the network where the subnet is being searched for. prefix: Prefix6 – Subnet prefix.
Public property: subnets(limit: Optional[int] = DEFAULT_IPV6_SUBNET_LIMIT): List[Network6] – Deprecated helper returning subnet list with an optional safety limit. iter_subnets(limit: Optional[int] = DEFAULT_IPV6_SUBNET_LIMIT) -> Iterator[Network6] – Lazy subnet iterator.
- __setattr__(name, value)¶
Prevent dynamic attribute assignment on instances.
### Raises: * AttributeError: Attribute not previously declared.
- __init__(network, prefix)[source]¶
Constructor.
### Arguments: * network: Network6 - IPv6 network address object. * prefix: Prefix6 - Prefix object defining the subnet size.
- subnets(limit=4096)[source]¶
Return subnets list. (Deprecated)
### Arguments: * limit: Optional[int] - Maximum number of subnetworks allowed before raising. Defaults to DEFAULT_IPV6_SUBNET_LIMIT.
### Returns: [List[Network6]] - Generated IPv6 subnetworks.
### Raises: * ValueError: Propagated from iter_subnets() when the subnet count exceeds the configured limit.
- iter_subnets(limit=4096)[source]¶
Yield IPv6 subnetworks lazily.
### Arguments: * limit: Optional[int] - Maximum number of subnetworks allowed before raising. Defaults to DEFAULT_IPV6_SUBNET_LIMIT.
### Returns: Iterator[Network6] - Generator producing IPv6 subnetworks in ascending order.
### Raises: * ValueError: Raised when the subnet count exceeds the configured limit.