Python 3.3+ipaddressterm
ipaddress.IPv4Interface
interfaces
An IPv4 address together with the network it belongs to: the whole '10.1.2.3/8', without clearing the host bits.
Syntax
ipaddress.IPv4Interface(address)
It is a subclass of IPv4Address: isinstance(iface, IPv4Address) is true, so an interface can go wherever an address is expected. Comparison includes the mask, though, so IPv4Interface('1.2.3.4/24') == IPv4Address('1.2.3.4') is false; compare iface.ip instead. The network is .network, the prefix notation is .with_prefixlen.
Examples
import ipaddress
iface = ipaddress.IPv4Interface('10.1.2.3/8')
print(iface.ip, iface.network, iface.netmask) # → 10.1.2.3 10.0.0.0/8 255.0.0.0
print(isinstance(iface, ipaddress.IPv4Address)) # → True
print(iface == ipaddress.IPv4Address('10.1.2.3'), iface.ip == ipaddress.IPv4Address('10.1.2.3')) # → False True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy