On this page
ipaddress.ip_address
Prev: ipaddress.get_mixed_type_key | Up: ipaddress | Next: ipaddress.ip_interface
Rel: ipaddress.AddressValueError, ipaddress.collapse_addresses, ipaddress.get_mixed_type_key, ipaddress.ip_interface
Ref: docs.python.org — ipaddress.ip_address
Tags: #public #python3 #stdlib #ipaddress
Import
import ipaddress
from ipaddress import ip_address
Signature & Overview
ipaddress.ip_address(address)
Take an IP string/int and return an object of the correct type.
Usage
import ipaddress
assert ipaddress.ip_address("127.0.0.1").version == 4
assert ipaddress.ip_address("::1").version == 6
Gotchas
- Auto-detects IPv4 vs. IPv6: Best entry point for validating user-supplied IP strings.
REPL Inspect
from ipaddress import ip_address
help(ip_address)
Linked from
- tuts/python3/stdlib_module/ipaddress
- tuts/python3/stdlib_module/ipaddress/AddressValueError
- tuts/python3/stdlib_module/ipaddress/collapse_addresses
- tuts/python3/stdlib_module/ipaddress/get_mixed_type_key
- tuts/python3/stdlib_module/ipaddress/ip_interface
- tuts/python3/stdlib_module/ipaddress/ip_network
- tuts/python3/stdlib_module/ipaddress/IPv4Address
- tuts/python3/stdlib_module/ipaddress/IPv4Interface
- tuts/python3/stdlib_module/ipaddress/IPv4Network
- tuts/python3/stdlib_module/ipaddress/IPv6Address
- tuts/python3/stdlib_module/ipaddress/IPv6Interface
- tuts/python3/stdlib_module/ipaddress/IPv6Network
- tuts/python3/stdlib_module/ipaddress/NetmaskValueError
- tuts/python3/stdlib_module/ipaddress/summarize_address_range
- tuts/python3/stdlib_module/ipaddress/v4_int_to_packed
- tuts/python3/stdlib_module/ipaddress/v6_int_to_packed
Related notes
- tuts/python3/stdlib_module/ipaddress/AddressValueError Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/collapse_addresses Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/get_mixed_type_key Linked here; links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/ip_interface 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/ip_network links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Address links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Interface links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv4Network links to this page; shared tags: #ipaddress, #stdlib
- tuts/python3/stdlib_module/ipaddress/IPv6Address links to this page; shared tags: #ipaddress, #stdlib