public class MoreInetAddresses extends Object
InetAddress instances and not already provided in InetAddresses.
Unlike InetAddresses these methods, all provide full support for IPV6 "IPv4 mapped"
addresses "::ffff:192.168.0.1" inside an Inet6Address container. This is a deviation from the
InetAddress.getAddress() functionality which will automatically create an Inet4Address for these addresses. That
behavior, however, can be problematic during serialization and comparisons for InetAddresses.| Modifier and Type | Class and Description |
|---|---|
static class |
MoreInetAddresses.CidrInfo
Used to provide subnet information about a CIDR
|
| Modifier and Type | Method and Description |
|---|---|
static Inet4Address |
decrement(Inet4Address ip)
Returns a new Inet4Address that is one less than the passed in address.
|
static Inet6Address |
decrement(Inet6Address ip)
Returns a new Inet6Address that is one less than the passed in address.
|
static Inet4Address |
forIPv4String(String ipString)
Generates a new Inet4Address instance from the provided address.
|
static Inet6Address |
forIPv6String(String ipString)
Generates a new
Inet6Address instance from the provided address. |
static InetAddress |
forString(String ipString)
Returns the
InetAddress having the given string representation. |
static Inet4Address |
getEmbeddedIPv4ClientAddress(Inet6Address ip)
Examines the Inet6Address to extract the embedded IPv4 client address
if the InetAddress is an IPv6 address of one of the specified address
types that contain an embedded IPv4 address.
|
static Inet6Address |
getIPV4CompatIPv6Address(Inet4Address ip)
Generates an "IPv4 compatible"
Inet6Address from the provided Inet4Address. |
static Inet6Address |
getIPv4MappedIPv6Address(Inet4Address ip)
Generates an "IPv4 mapped"
Inet6Address from the provided Inet4Address. |
static Inet4Address |
getMappedIPv4Address(Inet6Address ip)
Returns the IPv4 address embedded in an IPv4 mapped address.
|
static boolean |
hasEmbeddedIPv4ClientAddress(Inet6Address ip)
Examines the Inet6Address to determine if it is an IPv6 address of one
of the specified address types that contain an embedded IPv4 address.
|
static Inet4Address |
increment(Inet4Address ip)
Returns a new Inet4Address that is one more than the passed in address.
|
static Inet6Address |
increment(Inet6Address ip)
Returns a new Inet6Address that is one more than the passed in address.
|
static boolean |
isMappedIPv4Address(Inet6Address ip)
Evaluates whether the argument is an IPv6 "mapped" address.
|
static MoreInetAddresses.CidrInfo |
parseCIDR(String cidr)
Examines a CIDR
192.168.0.0/16 or 1234::/16 string representation and calculates the network and
broadcast IP addresses for that subnet. |
public static InetAddress forString(String ipString)
InetAddress having the given string representation. It additionally respects
IPV6 "IPv4 mapped" addresses, "::ffff:192.168.0.1" as an Inet6Address.
This deliberately avoids all nameservice lookups (e.g. no DNS).
NOTE: This simply extends the InetAddresses.forString functionality
to support "IPv4 mapped" addresses.
ipString - String containing an IPv4 or IPv6 string literal, e.g.
"192.168.0.1" or "2001:db8::1"InetAddress representing the argumentIllegalArgumentException - if the argument is not a valid IP string literalpublic static Inet4Address forIPv4String(String ipString)
InetAddress.getByName().public static Inet6Address forIPv6String(String ipString)
Inet6Address instance from the provided address. This will NOT do a dns lookup on the address if it
does not represent a valid ip address like InetAddress.getByName().
If the provided string is an ipv4 "mapped" address ('ffff:x.x.x.x' this method will still generate a valid Inet6Address
instance.public static boolean isMappedIPv4Address(Inet6Address ip)
An "IPv4 mapped", or "mapped", address is one with 80 leading
bits of zero followed by 16 bits of 1, with the remaining 32 bits interpreted as an
IPv4 address. These are conventionally represented in string
literals as "::ffff:192.168.0.1", though "::ffff:c0a8:1" is
also considered an IPv4 compatible address (and equivalent to
"::192.168.0.1").
ip - Inet6Address to be examined for embedded IPv4 mapped address formattrue if the argument is a valid "mapped" addresspublic static Inet4Address getMappedIPv4Address(Inet6Address ip)
ip - Inet6Address to be examined for an embedded IPv4 addressInet4Address of the embedded IPv4 addressIllegalArgumentException - if the argument is not a valid IPv4 mapped addresspublic static boolean hasEmbeddedIPv4ClientAddress(Inet6Address ip)
NOTE: This simply extends the InetAddresses.hasEmbeddedIPv4ClientAddress functionality
to support "IPv4 mapped" addresses.
ip - Inet6Address to be examined for embedded IPv4 client addresstrue if there is an embedded IPv4 client addresspublic static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip)
NOTE: This simply extends the InetAddresses.getEmbeddedIPv4ClientAddress functionality
to support "IPv4 mapped" addresses.
ip - Inet6Address to be examined for embedded IPv4 client addressInet4Address of embedded IPv4 client addressIllegalArgumentException - if the argument does not have a valid embedded IPv4 addresspublic static Inet6Address getIPv4MappedIPv6Address(Inet4Address ip)
Inet6Address from the provided Inet4Address.public static Inet6Address getIPV4CompatIPv6Address(Inet4Address ip)
Inet6Address from the provided Inet4Address.public static Inet4Address increment(Inet4Address ip)
ip - the Inet4Address to incrementIllegalArgumentException - if Inet4Address is at the end of its rangepublic static Inet6Address increment(Inet6Address ip)
ip - the Inet6Address to incrementIllegalArgumentException - if Inet6Address is at the end of its rangepublic static Inet4Address decrement(Inet4Address ip)
ip - the Inet4Address to decrementIllegalArgumentException - if Inet4Address is at the beginning of its rangepublic static Inet6Address decrement(Inet6Address ip)
ip - the Inet6Address to decrementIllegalArgumentException - if Inet6Address is at the beginning of its rangepublic static MoreInetAddresses.CidrInfo parseCIDR(String cidr)
192.168.0.0/16 or 1234::/16 string representation and calculates the network and
broadcast IP addresses for that subnet. This accepts both IPv4 and IPv6 representations of a CIDR and will return
the appropriate InetAddress classes for the provided value.
Note: This supports IPv6 "IPv4 mapped" addresses and will create a valid Inet6Address to account for them.
Copyright © 2018 Calrissian. All rights reserved.