public final class Inet
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
static java.net.Inet4Address |
INET4_ANY |
The "any" address for IPv4.
|
static java.net.Inet4Address |
INET4_BROADCAST |
The broadcast-all address for IPv4.
|
static java.net.Inet4Address |
INET4_LOOPBACK |
The traditional loopback address for IPv4.
|
static java.net.Inet6Address |
INET6_ANY |
The "any" address for IPv6.
|
static java.net.Inet6Address |
INET6_LOOPBACK |
The loopback address for IPv6.
|
| Modifier and Type | Method | Description |
|---|---|---|
static java.net.NetworkInterface |
findInterfaceWithScopeId(java.lang.String scopeName) |
|
static <T extends java.net.InetAddress> |
getAddressByNameAndType(java.lang.String hostName,
java.lang.Class<T> addressType) |
Resolve the given host name, returning the first answer with the given address type.
|
static <T extends java.net.InetAddress> |
getAllAddressesByNameAndType(java.lang.String hostName,
java.lang.Class<T> addressType) |
Resolve the given host name, returning all answers with the given address type.
|
static java.lang.String |
getHostNameIfResolved(java.net.InetAddress inetAddress) |
Get the host name of the given address, if it is resolved.
|
static java.net.Inet4Address |
getInet4Address(int s1,
int s2,
int s3,
int s4) |
Get an IPv4 address from four integer segments.
|
static java.net.Inet6Address |
getInet6Address(int s1,
int s2,
int s3,
int s4,
int s5,
int s6,
int s7,
int s8) |
Get an IPv6 address from eight integer segments.
|
static java.net.InetSocketAddress |
getResolved(java.net.InetSocketAddress address) |
Get a copy of the given socket address, but with a resolved address component.
|
static java.net.InetSocketAddress |
getResolved(java.net.InetSocketAddress address,
java.lang.Class<? extends java.net.InetAddress> addressType) |
Get a copy of the given socket address, but with a resolved address component of the given type.
|
static java.net.InetSocketAddress |
getResolved(java.net.URI uri,
int defaultPort) |
Get the resolved socket address from the given URI.
|
static java.net.InetSocketAddress |
getResolved(java.net.URI uri,
int defaultPort,
java.lang.Class<? extends java.net.InetAddress> addressType) |
Get a resolved socket address from the given URI.
|
static int |
getScopeId(java.lang.String scopeName) |
Attempt to get the scope ID of the given string.
|
static int |
getScopeId(java.lang.String scopeName,
java.net.InetAddress compareWith) |
Attempt to get the scope ID of the given string.
|
static int |
getScopeId(java.net.InetAddress address) |
Get the scope ID of the given address (if it is an IPv6 address).
|
static int |
getScopeId(java.net.NetworkInterface networkInterface) |
|
static int |
getScopeId(java.net.NetworkInterface networkInterface,
java.net.InetAddress compareWith) |
|
static boolean |
isInet4Address(java.lang.String address) |
Checks whether given String is a valid IPv4 address.
|
static boolean |
isInet6Address(java.lang.String address) |
Checks whether given String is a valid IPv6 address.
|
static CidrAddress |
parseCidrAddress(java.lang.String address) |
Parse a CIDR address into a
CidrAddress object. |
static java.net.Inet4Address |
parseInet4Address(java.lang.String address) |
Parse an IPv4 address into an
Inet4Address object. |
static java.net.Inet4Address |
parseInet4Address(java.lang.String address,
java.lang.String hostName) |
Parse an IPv4 address into an
Inet4Address object. |
static java.net.Inet4Address |
parseInet4AddressOrFail(java.lang.String address) |
Parse an IPv4 address into an
Inet4Address object, throwing an exception on failure. |
static java.net.Inet4Address |
parseInet4AddressOrFail(java.lang.String address,
java.lang.String hostName) |
Parse an IPv4 address into an
Inet4Address object. |
static byte[] |
parseInet4AddressToBytes(java.lang.String address) |
Converts IPv4 address from textual representation to bytes.
|
static java.net.Inet6Address |
parseInet6Address(java.lang.String address) |
Parse an IPv6 address into an
Inet6Address object. |
static java.net.Inet6Address |
parseInet6Address(java.lang.String address,
java.lang.String hostName) |
Parse an IPv6 address into an
Inet6Address object. |
static java.net.Inet6Address |
parseInet6AddressOrFail(java.lang.String address) |
Parse an IPv6 address into an
Inet6Address object, throwing an exception on failure. |
static java.net.Inet6Address |
parseInet6AddressOrFail(java.lang.String address,
java.lang.String hostName) |
Parse an IPv6 address into an
Inet6Address object. |
static byte[] |
parseInet6AddressToBytes(java.lang.String address) |
Converts IPv6 address from textual representation to bytes.
|
static java.net.InetAddress |
parseInetAddress(java.lang.String address) |
Parse an IP address into an
InetAddress object. |
static java.net.InetAddress |
parseInetAddress(java.lang.String address,
java.lang.String hostName) |
Parse an IP address into an
InetAddress object. |
static java.net.InetAddress |
parseInetAddressOrFail(java.lang.String address) |
Parse an IP address into an
InetAddress object, throwing an exception on failure. |
static java.net.InetAddress |
parseInetAddressOrFail(java.lang.String address,
java.lang.String hostName) |
Parse an IP address into an
InetAddress object. |
static byte[] |
parseInetAddressToBytes(java.lang.String address) |
Converts an IP address from textual representation to bytes.
|
static java.net.Inet6Address |
toInet6Address(java.net.InetAddress inetAddress) |
Get the IPv6 equivalent of the given address.
|
static java.lang.String |
toOptimalString(byte[] addressBytes) |
Get the optimal string representation of the bytes of an IP address.
|
static java.lang.String |
toOptimalString(java.net.InetAddress inetAddress) |
Get the optimal string representation of an IP address.
|
static java.lang.String |
toURLString(byte[] addressBytes) |
Get a string representation of the given address bytes which is suitable for use as the host component of a URL.
|
static java.lang.String |
toURLString(java.net.InetAddress inetAddress,
boolean useHostNameIfPresent) |
Get a string representation of the given address which is suitable for use as the host component of a URL.
|
public static final java.net.Inet4Address INET4_ANY
public static final java.net.Inet4Address INET4_LOOPBACK
public static final java.net.Inet4Address INET4_BROADCAST
public static final java.net.Inet6Address INET6_ANY
public static final java.net.Inet6Address INET6_LOOPBACK
public static java.lang.String toOptimalString(java.net.InetAddress inetAddress)
inetAddress - the address (must not be null)null)public static java.lang.String toOptimalString(byte[] addressBytes)
addressBytes - the address bytes (must not be null)null)public static java.lang.String toURLString(java.net.InetAddress inetAddress,
boolean useHostNameIfPresent)
inetAddress - the address (must not be null)useHostNameIfPresent - true to preserve the host name string in the address, false to always give
an IP address stringnull)public static java.lang.String toURLString(byte[] addressBytes)
addressBytes - the address bytes (must not be null)null)public static java.net.Inet6Address toInet6Address(java.net.InetAddress inetAddress)
inetAddress - the address to convert (must not be null)null)public static java.lang.String getHostNameIfResolved(java.net.InetAddress inetAddress)
null.inetAddress - the address to check (must not be null)null if the address has no host name and is unresolvedpublic static java.net.InetSocketAddress getResolved(java.net.URI uri,
int defaultPort,
java.lang.Class<? extends java.net.InetAddress> addressType)
throws java.net.UnknownHostException
uri - the URI (must not be null)defaultPort - the default port to use if none is given (must be in the range 1 \u2264 n \u2264 65535addressType - the class of the InetAddress to search for (must not be null)null if the URI does not have a host componentjava.net.UnknownHostException - if address resolution failedpublic static java.net.InetSocketAddress getResolved(java.net.URI uri,
int defaultPort)
throws java.net.UnknownHostException
uri - the URI (must not be null)defaultPort - the default port to use if none is given (must be in the range 1 \u2264 n \u2264 65535null if the URI does not have a host componentjava.net.UnknownHostException - if address resolution failedpublic static java.net.InetSocketAddress getResolved(java.net.InetSocketAddress address)
throws java.net.UnknownHostException
address - the (possibly unresolved) address (must not be null)null)java.net.UnknownHostException - if address resolution failedpublic static java.net.InetSocketAddress getResolved(java.net.InetSocketAddress address,
java.lang.Class<? extends java.net.InetAddress> addressType)
throws java.net.UnknownHostException
address - the (possibly unresolved) address (must not be null)addressType - the class of the InetAddress to search for (must not be null)null)java.net.UnknownHostException - if address resolution failed, or if no addresses of the given type were found, or
if the given address was already resolved but is not of the given address typepublic static <T extends java.net.InetAddress> T getAddressByNameAndType(java.lang.String hostName,
java.lang.Class<T> addressType)
throws java.net.UnknownHostException
T - the type of the InetAddress to search forhostName - the host name to resolve (must not be null)addressType - the class of the InetAddress to search for (must not be null)null)java.net.UnknownHostException - if address resolution failed or if no addresses of the given type were foundpublic static <T extends java.net.InetAddress> T[] getAllAddressesByNameAndType(java.lang.String hostName,
java.lang.Class<T> addressType)
throws java.net.UnknownHostException
T - the type of the InetAddress to search forhostName - the host name to resolve (must not be null)addressType - the class of the InetAddress to search for (must not be null)null)java.net.UnknownHostException - if address resolution failed or if no addresses of the given type were foundpublic static java.net.Inet4Address getInet4Address(int s1,
int s2,
int s3,
int s4)
s1 - the first segments2 - the second segments3 - the third segments4 - the fourth segmentnull)public static java.net.Inet6Address getInet6Address(int s1,
int s2,
int s3,
int s4,
int s5,
int s6,
int s7,
int s8)
0xffff).s1 - the first segments2 - the second segments3 - the third segments4 - the fourth segments5 - the fifth segments6 - the sixth segments7 - the seventh segments8 - the eighth segmentnull)public static boolean isInet6Address(java.lang.String address)
address - address textual representationtrue if address is a valid IPv6 address, false otherwisepublic static java.net.Inet6Address parseInet6Address(java.lang.String address)
Inet6Address object.address - the address to parsenull if the address is not validpublic static java.net.Inet6Address parseInet6Address(java.lang.String address,
java.lang.String hostName)
Inet6Address object.address - the address to parse (must not be null)hostName - the host name to use in the resultant object, or null to use the string representation of
the addressnull if the address is not validpublic static java.net.Inet6Address parseInet6AddressOrFail(java.lang.String address)
Inet6Address object, throwing an exception on failure.address - the address to parsenull)java.lang.IllegalArgumentException - if the address is not validpublic static java.net.Inet6Address parseInet6AddressOrFail(java.lang.String address,
java.lang.String hostName)
Inet6Address object.address - the address to parse (must not be null)hostName - the host name to use in the resultant object, or null to use the string representation of
the addressnull)java.lang.IllegalArgumentException - if the address is not validpublic static boolean isInet4Address(java.lang.String address)
address - address textual representationtrue if address is a valid IPv4 address, false otherwisepublic static java.net.Inet4Address parseInet4Address(java.lang.String address)
Inet4Address object.address - the address to parsenull if the address is not validpublic static java.net.Inet4Address parseInet4Address(java.lang.String address,
java.lang.String hostName)
Inet4Address object.address - the address to parsehostName - the host name to use in the resultant object, or null to use the string representation of
the addressnull if the address is not validpublic static java.net.Inet4Address parseInet4AddressOrFail(java.lang.String address)
Inet4Address object, throwing an exception on failure.address - the address to parsenull)java.lang.IllegalArgumentException - if the address is not validpublic static java.net.Inet4Address parseInet4AddressOrFail(java.lang.String address,
java.lang.String hostName)
Inet4Address object.address - the address to parse (must not be null)hostName - the host name to use in the resultant object, or null to use the string representation of
the addressnull)java.lang.IllegalArgumentException - if the address is not validpublic static java.net.InetAddress parseInetAddress(java.lang.String address)
InetAddress object.address - the address to parsenull if the address is not validpublic static java.net.InetAddress parseInetAddress(java.lang.String address,
java.lang.String hostName)
InetAddress object.address - the address to parsehostName - the host name to use in the resultant object, or null to use the string representation of
the addressnull if the address is not validpublic static java.net.InetAddress parseInetAddressOrFail(java.lang.String address)
InetAddress object, throwing an exception on failure.address - the address to parsenull)java.lang.IllegalArgumentException - if the address is not validpublic static java.net.InetAddress parseInetAddressOrFail(java.lang.String address,
java.lang.String hostName)
InetAddress object.address - the address to parse (must not be null)hostName - the host name to use in the resultant object, or null to use the string representation of
the addressnull)java.lang.IllegalArgumentException - if the address is not validpublic static CidrAddress parseCidrAddress(java.lang.String address)
CidrAddress object.address - the address to parsenull if the address is not validpublic static byte[] parseInet6AddressToBytes(java.lang.String address)
If given string doesn't represent valid IPv6 address, the method returns null.
address - address textual representationnull if the address is not validpublic static byte[] parseInet4AddressToBytes(java.lang.String address)
If given string doesn't represent valid IPv4 address, the method returns null.
This only supports decimal notation.
address - address textual representationnull if the address is not validpublic static byte[] parseInetAddressToBytes(java.lang.String address)
If given string doesn't represent valid IP address, the method returns null.
address - address textual representationnull if the address is not validpublic static int getScopeId(java.net.InetAddress address)
public static int getScopeId(java.lang.String scopeName)
scopeName - the scope number or name as a string (must not be null)public static int getScopeId(java.lang.String scopeName,
java.net.InetAddress compareWith)
scopeName - the scope number or name as a string (must not be null)compareWith - the address to compare with, to ensure that the wrong local scope is not selected (may be null)public static java.net.NetworkInterface findInterfaceWithScopeId(java.lang.String scopeName)
public static int getScopeId(java.net.NetworkInterface networkInterface)
public static int getScopeId(java.net.NetworkInterface networkInterface,
java.net.InetAddress compareWith)
Copyright © 2017 JBoss, a division of Red Hat, Inc.