On this page
ipaddress.ip_network
Prev: ipaddress.ip_interface | Up: ipaddress | Next: ipaddress.IPv4Address
Rel: ipaddress.AddressValueError, ipaddress.collapse_addresses, ipaddress.get_mixed_type_key, ipaddress.ip_address
Ref: docs.python.org — ipaddress.ip_network
Tags: #public #python3 #stdlib #ipaddress
Import
import ipaddress
from ipaddress import ip_network
Signature & Overview
ipaddress.ip_network(address, strict=True)
Take an IP string/int and return an object of the correct type.
Usage
import ipaddress
net = ipaddress.ip_network("10.0.0.5/24", strict=False)
assert str(net) == "10.0.0.0/24"
Gotchas
- Defaults to
strict=True: Passstrict=Falseto mask off host bits automatically.
REPL Inspect
from ipaddress import ip_network
help(ip_network)
Linked from
Related notes
- tuts/python3/stdlib_module/ipaddress/ip_interface Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Address 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/IPv4Interface shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Network shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv6Address shared tags: #ipaddress, #stdlib