On this page
ipaddress.IPv4Address
Prev: ipaddress.ip_network | Up: ipaddress | Next: ipaddress.IPv4Interface
Rel: ipaddress.AddressValueError, ipaddress.collapse_addresses, ipaddress.get_mixed_type_key, ipaddress.ip_address
Ref: docs.python.org — ipaddress.IPv4Address
Tags: #public #python3 #stdlib #ipaddress
Import
import ipaddress
from ipaddress import IPv4Address
Signature & Overview
ipaddress.IPv4Address(address)
Represent and manipulate single IPv4 Addresses.
Methods & Attributes
IPv4Address.compressed(...)— Return the shorthand version of the IP address as a string.IPv4Address.exploded(...)— Return the longhand version of the IP address as a string.IPv4Address.ipv6_mapped(...)— Return the IPv4-mapped IPv6 address.IPv4Address.is_global(...)—Trueif the address is defined as globally reachable by iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_ (for IPv6) with the following exception:IPv4Address.is_link_local(...)— Test if the address is reserved for link-local.IPv4Address.is_loopback(...)— Test if the address is a loopback address.IPv4Address.is_multicast(...)— Test if the address is reserved for multicast use.IPv4Address.is_private(...)—Trueif the address is defined as not globally reachable by iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_ (for IPv6) with the following exceptions:IPv4Address.is_reserved(...)— Test if the address is otherwise IETF reserved.IPv4Address.is_unspecified(...)— Test if the address is unspecified.IPv4Address.packed(...)— The binary representation of this address.IPv4Address.reverse_pointer(...)— The name of the reverse DNS pointer for the IP address, e.g.: >>> ipaddress.ip_address("127.0.0.1").reverse_pointer '1.0.0.127.in-addr.arpa'
Usage
import ipaddress
ip = ipaddress.IPv4Address("192.168.1.10")
assert ip.is_private and not ip.is_global and int(ip) > 0
Gotchas
- Strict parsing: Rejects leading zeros (
"192.168.01.1") and CIDR masks (useIPv4InterfaceorIPv4Networkfor/24).
REPL Inspect
from ipaddress import IPv4Address
help(IPv4Address)
Linked from
Related notes
- tuts/python3/stdlib_module/ipaddress/ip_network Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Interface Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ipaddress/AddressValueError Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/collapse_addresses Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/get_mixed_type_key Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/ip_address Linked here; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/ip_interface shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Network shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv6Address shared tags: #ipaddress, #stdlib