class ipaddress.IPv4Address(address)
Construct an IPv4 address. An AddressValueError
is raised if address is not a valid IPv4 address.
The following constitutes a valid IPv4 address:
- A string in decimal-dot notation, consisting of four decimal integers in the inclusive range 0-255, separated by dots (e.g.
192.168.0.1
). Each integer represents an octet (byte) in the address. Leading zeroes are tolerated only for values less than 8 (as there is no ambiguity between the decimal and octal interpretations of such strings). - An integer that fits into 32 bits.
- An integer packed into a
bytes
object of length 4 (most significant octet first).
>>> ipaddress.IPv4Address('192.168.0.1') IPv4Address('192.168.0.1') >>> ipaddress.IPv4Address(3232235521) IPv4Address('192.168.0.1') >>> ipaddress.IPv4Address(b'\xC0\xA8\x00\x01') IPv4Address('192.168.0.1')
-
version
-
The appropriate version number:
4
for IPv4,6
for IPv6.
-
max_prefixlen
-
The total number of bits in the address representation for this version:
32
for IPv4,128
for IPv6.The prefix defines the number of leading bits in an address that are compared to determine whether or not an address is part of a network.
-
compressed
-
exploded
-
The string representation in dotted decimal notation. Leading zeroes are never included in the representation.
As IPv4 does not define a shorthand notation for addresses with octets set to zero, these two attributes are always the same as
str(addr)
for IPv4 addresses. Exposing these attributes makes it easier to write display code that can handle both IPv4 and IPv6 addresses.
-
packed
-
The binary representation of this address - a
bytes
object of the appropriate length (most significant octet first). This is 4 bytes for IPv4 and 16 bytes for IPv6.
-
reverse_pointer
-
The name of the reverse DNS PTR record for the IP address, e.g.:
>>> ipaddress.ip_address("127.0.0.1").reverse_pointer '1.0.0.127.in-addr.arpa' >>> ipaddress.ip_address("2001:db8::1").reverse_pointer '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
This is the name that could be used for performing a PTR lookup, not the resolved hostname itself.
New in version 3.5.
-
is_multicast
-
True
if the address is reserved for multicast use. See RFC 3171 (for IPv4) or RFC 2373 (for IPv6).
-
is_private
-
True
if the address is allocated for private networks. See iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-registry (for IPv6).
-
is_global
-
True
if the address is allocated for public networks. See iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-registry (for IPv6).New in version 3.4.
-
is_reserved
-
True
if the address is otherwise IETF reserved.
-
is_link_local
-
True
if the address is reserved for link-local usage. See RFC 3927.
Please login to continue.