

To determine the appropriate network address. If strict is True and host bits are set in the supplied address, A NetmaskValueError is raised if the mask is not valid for 255.255.255.0).Īn AddressValueError is raised if address is not a valid IPv4Īddress. Integer, or an existing IPv4Address object and the netmask is eitherĪn integer representing the prefix length (e.g.

The interpretation is similar to an integer address.Ī two-tuple of an address description and a netmask, where the addressĭescription is either a string, a 32-bits integer, a 4-bytes packed Single-address network, with the network address being address andĪn integer packed into a bytes object of length 4, big-endian. If no mask is provided,įor example, the following address specifications are equivalent:ġ92.168.1.0/24, 192.168.1.0/255.255.255.0 andĪn integer that fits into 32 bits. Host mask if it starts with a zero field, with the single exception ofĪn all-zero mask which is treated as a net mask. Interpreted as a net mask if it starts with a non-zero field, or as a The IP address is the network address, and the maskĬan be either a single number, which means it’s a prefix, or a string address can be one of the following:Ī string consisting of an IP address and an optional mask, separated byĪ slash ( /). IPv4Network ( address, strict = True ) ¶Ĭonstruct an IPv4 network definition. Network objects are hashable, so they can be used as keys inĭictionaries. So to avoid duplication they are only documented for IPv4Network. In addition, network objects implement additional attributes.Īll of these are common between IPv4Network and IPv6Network, Refer to the corresponding method documentation inĪll attributes implemented by address objects are implemented by network For any otherĪddress, this property will be None. The embedded (server, client) IP address pair. For any other address, this property willįor addresses that appear to be Teredo addresses (starting withĢ001::/32) as defined by RFC 4380, this property will report sixtofour ¶įor addresses that appear to be 6to4 addresses (starting withĢ002::/16) as defined by RFC 3056, this property will report When no scope zone is specified, this property will be None.

The particular zone of the address’s scope that the address belongs to,Īs a string. scope_id ¶įor scoped addresses as defined by RFC 4007, this property identifies ::FFFF/96), this property will report the embedded IPv4 address.įor any other address, this property will be None. ipv4_mapped ¶įor addresses that appear to be IPv4 mapped addresses (starting with Space of unique local addresses as defined by RFC 4193. Is_private to test if this address is in the The site-local address space has been deprecated by RFC 3879. True if the address is reserved for site-local usage. New in version 3.4: is_global is_site_local ¶ The name of the reverse DNS PTR record for the IP address, e.g.: This is 4 bytesįor IPv4 and 16 bytes for IPv6. The appropriate length (most significant octet first). The binary representation of this address - a bytes object of
#255 255 255 128 PREFIX NOTATION CODE#
Write display code that can handle both IPv4 and IPv6 addresses. Exposing these attributes makes it easier to Set to zero, these two attributes are always the same as str(addr)įor IPv4 addresses. Leading zeroesĪre never included in the representation.Īs IPv4 does not define a shorthand notation for addresses with octets

The string representation in dotted decimal notation. The prefix defines the number of leading bits in an address thatĪre compared to determine whether or not an address is part of a The total number of bits in the address representation for this The appropriate version number: 4 for IPv4, 6 for IPv6. Changed in version 3.8.12: The above change was also included in Python 3.8 starting with
