ipaddress.ip_network()
ipaddress.ip_network() is a Python function in the IP Address Module category. Creates an IPv4Network or IPv6Network object from an IP network string. The syntax is ipaddress.ip_network(address, strict=True). Returns: IPv4Network or IPv6Network. A typical example: net = ipaddress.ip_network("192.168.0.0/16")
net.netmask # IPv4Address("255.255.0.0")
net.num_addresses # 65536. A close sibling is ipaddress.ip_address(), which creates an IPv4Address or IPv6Address object from a string. A close sibling is ipaddress.ip_interface(), which creates an IPv4Interface or IPv6Interface (host with network). A close sibling is IPv4Address.is_private, which returns True if the address is in a private IP range. A close sibling is IPv4Address.is_loopback, which returns True if the address is a loopback address (127.0.0.0/8). More about this category: IP address handling — IPv4Address, IPv6Address, IPv4Network, IPv6Network. Related IP Address Module entries: ipaddress.ip_address(), ipaddress.ip_interface(), IPv4Address.is_private, IPv4Address.is_loopback, IPv4Address.is_multicast, IPv4Address.is_global. This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.