On this page
ipaddress.IPv4Network
Prev: ipaddress.IPv4Interface | Up: ipaddress | Next: ipaddress.IPv6Address
Rel: ipaddress.AddressValueError, ipaddress.collapse_addresses, ipaddress.get_mixed_type_key, ipaddress.ip_address
Ref: docs.python.org — ipaddress.IPv4Network
Tags: #public #python3 #stdlib #ipaddress
Import
import ipaddress
from ipaddress import IPv4Network
Signature & Overview
ipaddress.IPv4Network(address, strict=True)
This class represents and manipulates 32-bit IPv4 network + addresses..
Methods & Attributes
IPv4Network.address_exclude(self, other)— Remove an address from a larger block.IPv4Network.compare_networks(self, other)— Compare two IP objects.IPv4Network.compressed(...)— Return the shorthand version of the IP address as a string.IPv4Network.exploded(...)— Return the longhand version of the IP address as a string.IPv4Network.hosts(self)— Generate Iterator over usable hosts in a network.IPv4Network.is_global(...)— Test if this address is allocated for public networks.IPv4Network.is_link_local(...)— Test if the address is reserved for link-local.IPv4Network.is_loopback(...)— Test if the address is a loopback address.IPv4Network.is_multicast(...)— Test if the address is reserved for multicast use.IPv4Network.is_private(...)— Test if this network belongs to a private range.IPv4Network.is_reserved(...)— Test if the address is otherwise IETF reserved.IPv4Network.is_unspecified(...)— Test if the address is unspecified.IPv4Network.num_addresses(...)— Number of hosts in the current subnet.IPv4Network.overlaps(self, other)— Tell if self is partly contained in other.IPv4Network.prefixlen(...)—IPv4Network.prefixlenmethod/property.IPv4Network.reverse_pointer(...)— The name of the reverse DNS pointer for the IP address, e.g.: >>> ipaddress.ip_address("127.0.0.1").reverse_pointer '1.0.0.127.in-addr.arpa'IPv4Network.subnet_of(self, other)— Return True if this network is a subnet of other.IPv4Network.subnets(self, prefixlen_diff=1, new_prefix=None)— The subnets which join to make the current subnet.IPv4Network.supernet(self, prefixlen_diff=1, new_prefix=None)— The supernet containing the current network.IPv4Network.supernet_of(self, other)— Return True if this network is a supernet of other.IPv4Network.with_hostmask(...)—IPv4Network.with_hostmaskmethod/property.IPv4Network.with_netmask(...)—IPv4Network.with_netmaskmethod/property.IPv4Network.with_prefixlen(...)—IPv4Network.with_prefixlenmethod/property.
Usage
import ipaddress
net = ipaddress.IPv4Network("10.0.0.0/24")
assert ipaddress.IPv4Address("10.0.0.42") in net
assert net.num_addresses == 256
Gotchas
- Pass
strict=Falseif host bits are set:IPv4Network("10.0.0.5/24")raisesValueErrorunlessstrict=False.
REPL Inspect
from ipaddress import IPv4Network
help(IPv4Network)
Linked from
Related notes
- tuts/python3/stdlib_module/ipaddress/IPv4Interface Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv6Address Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ipaddress/AddressValueError Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/collapse_addresses Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/get_mixed_type_key Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/ip_address Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/ip_interface shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/ip_network shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Address shared tags: #ipaddress, #stdlib