Python Glossary Русский

Python 3.3+ipaddressfunction

ipaddress.ip_interface()

factory functions

Creates an IPv4Interface or IPv6Interface: a host address together with its network, as in '192.168.1.5/24' from a network card setting.

Syntax

ipaddress.ip_interface(address)

This is the answer to 'has host bits set': ip_network() rejects such notation, while an interface is exactly what it means. Read .ip for the address itself and .network for the network with host bits cleared. Equality takes the mask into account: 192.168.1.5/24 and 192.168.1.5/25 are different interfaces even though the address is the same.

Examples

import ipaddress
iface = ipaddress.ip_interface('192.168.1.5/24')
print(iface.ip, iface.network)  # → 192.168.1.5 192.168.1.0/24
print(iface == ipaddress.ip_interface('192.168.1.5/25'))  # → False

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy