>>> ipaddress.ip_network( '192.0.2.0/24 ') IPv4Network('192.0.2.0/24') >>> ipaddress.ip_network( '2001:db8::0/96 ') IPv6Network('2001:db8::/96') 

Network objects cannot have any host bits set. The practical effect of this is that 192.0.2.1/24 does not describe a network. Such definitions are referred to as interface objects since the ip-on-a-network notation is commonly used to describe network interfaces of a computer on a given network and are described further in the next section. 

By default, attempting to create a network object with host bits set will result in ValueError being raised. To request that the additional bits instead be coerced to zero, the flag strict=False can be passed to the constructor: 

>>> ipaddress.ip_network( '192.0.2.1/24 ') Traceback (most recent call last): ... ValueError: 192.0.2.1/24 has host bits set >>> ipaddress.ip_network( '192.0.2.1/24 ', strict= False ) IPv4Network('192.0.2.0/24') 

While the string form offers significantly more flexibility, networks can also be defined with integers, just like host addresses. In this case, the network is considered to contain only the single address identified by the integer, so the network prefix includes the entire network address: 

>>> ipaddress.ip_network( 3221225984 ) IPv4Network('192.0.2.0/32') >>> ipaddress.ip_network( 42540766411282592856903984951653826560 ) IPv6Network('2001:db8::/128') 

As with addresses, creation of a particular kind of network can be forced by calling the class constructor directly instead of using the factory function. 

## 1.4 Host Interfaces 

As mentioned just above, if you need to describe an address on a particular network, neither the address nor the network classes are sufficient. Notation like$_{192.0.2.1/24}$ is commonly used by network engineers and the people who write tools for firewalls and routers as shorthand for “the host$_{192.0.2.1}$ on the network$_{192.0.}$ 2.0/24 ”, Accordingly,$_{ipaddress}$ provides a set of hybrid classes that associate an address with a particular network. The interface for creation is identical to that for defining network objects, except that the address portion isn’t constrained to being a network address. 

>>> ipaddress.ip_interface( '192.0.2.1/24 ') IPv4Interface('192.0.2.1/24') >>> ipaddress.ip_interface( '2001:db8::1/96 ') IPv6Interface('2001:db8::1/96') 

Integer inputs are accepted (as with networks), and use of a particular IP version can be forced by calling the relevant constructor directly. 

