Converts this address to a value of type A
using the supplied functions.
Returns true if this address is in the multicast range.
Returns true if this address is in the source specific multicast range.
Gets the IP address after this address, with overflow from the maximum value to the minimum value.
Gets the IP address before this address, with underflow from minimum value to the maximum value.
Converts this address to a string form that is compatible for use in a URI per RFC3986 (namely, IPv6 addresses are rendered in condensed form and surrounded by brackets).
Maps a type-preserving function across this IP address.
Constructs a Cidr address from this address.
Narrows this address to an Ipv4Address if that is the underlying type.
Narrows this address to an Ipv6Address if that is the underlying type.
Converts this address to a multicast address, as long as it is in the multicast address range.
Converts this address to a source specific multicast address, as long as it is in the source specific multicast address range.
Converts this address to a network order byte array of either 4 or 16 bytes.
Immutable and safe representation of an IP address, either V4 or V6.
Construction
IpAddress
instances are constructed in a few different ways: - viaIpAddress("127.0.0.1")
, which parses a string representation of the IP and returns anOption[IpAddress]
- viaIpAddress.fromBytes(arr)
, which returns an IP address if the supplied array is either exactly 4 bytes or exactly 16 bytes - via literal syntax likeip"127.0.0.1"
, which returns anIpAddress
and fails to *compile* if the IP is invalid.Type Hierarchy
There are two subtypes of
IpAddress
-- Ipv4Address and Ipv6Address. Each of these subtypes have a richer API thanIpAddress
and it is often useful to use those types directly, for example if your use case requires a V6 address. It is safe to pattern match onIpAddress
to accessIpv4Address
orIpv6Address
directly, or alternatively, you can use fold.JVM Specific API
If using
IpAddress
on the JVM, you can calltoInetAddress
to convert the address to ajava.net.InetAddress
, for use with networking libraries. This method does not exist on the Scala.js version.