public class NetworkUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
IN_ADDR_ANY
A string containing the "any" local address.
|
static String |
IN4_ADDR_ANY
A string containing the "any" local address for IPv4.
|
private static int |
IN4_ADDR_SIZE
The length of IPv4 addresses.
|
static String |
IN6_ADDR_ANY
A string containing the "any" local address for IPv6.
|
private static int |
IN6_ADDR_SIZE
The length of IPv6 addresses.
|
private static int |
IN6_ADDR_TOKEN_SIZE
The size of the tokens in a String representation of IPv6
addresses.
|
private static Logger |
logger
Our class logger
|
static int |
MAX_PORT_NUMBER
The maximum int value that could correspond to a port number.
|
static int |
MIN_PORT_NUMBER
The minimum int value that could correspond to a port number bindable
by ice4j.
|
private static Random |
portNumberGenerator
The random port number generator that we use in getRandomPortNumer()
|
Constructor and Description |
---|
NetworkUtils() |
Modifier and Type | Method and Description |
---|---|
private static String |
determineAnyAddress()
Tries to determine if this host supports IPv6 addresses (i.e.
|
static InetAddress |
getInetAddress(String hostAddress)
Creates an InetAddress from the specified hostAddress.
|
static int |
getRandomPortNumber()
Returns a random local port number that user applications could bind to.
|
static int |
getRandomPortNumber(int min,
int max)
Returns a random local port number in the interval [min, max].
|
static boolean |
isInterfaceLoopback(NetworkInterface iface)
Determines whether or not the iface interface is a loopback
interface.
|
static boolean |
isInterfaceUp(NetworkInterface iface)
Determines, if possible, whether or not the iface interface is
up.
|
static boolean |
isInterfaceVirtual(NetworkInterface iface)
Determines, if possible, whether or not the iface interface is
a virtual interface (e.g.
|
static boolean |
isIPv4Address(String address)
Verifies whether address could be an IPv4 address string.
|
static boolean |
isIPv6Address(String address)
Verifies whether address could be an IPv6 address string.
|
private static boolean |
isMappedIPv4Addr(byte[] address)
Utility method to check if the specified address is an IPv4
mapped IPv6 address.
|
static boolean |
isValidIPAddress(String address)
Checks whether address is a valid IP address string.
|
static boolean |
isValidPortNumber(int port)
Determines whether port is a valid port number bindable by an
application (i.e.
|
static boolean |
isWindowsAutoConfiguredIPv4Address(InetAddress add)
Determines whether the address is the result of windows auto configuration.
|
static byte[] |
mappedIPv4ToRealIPv4(byte[] addr)
Returns an IPv4 address matching the one mapped in the IPv6
addr.
|
static String |
stripScopeID(String ipv6Address)
Returns a String that is guaranteed not to contain an address
scope specified (i.e.
|
static byte[] |
strToIPv4(String ipv4AddrStr)
Creates a byte array containing the specified ipv4AddStr.
|
static byte[] |
strToIPv6(String ipv6AddrStr)
Creates a byte array containing the specified ipv6AddStr.
|
private static final Logger logger
public static final String IN6_ADDR_ANY
private static final int IN6_ADDR_SIZE
private static final int IN6_ADDR_TOKEN_SIZE
public static final String IN4_ADDR_ANY
private static final int IN4_ADDR_SIZE
public static final String IN_ADDR_ANY
public static final int MAX_PORT_NUMBER
public static final int MIN_PORT_NUMBER
private static Random portNumberGenerator
public static boolean isWindowsAutoConfiguredIPv4Address(InetAddress add)
add
- the address to inspectpublic static int getRandomPortNumber()
public static int getRandomPortNumber(int min, int max)
min
- the minimum allowed value for the returned port number.max
- the maximum allowed value for the returned port number.public static boolean isIPv4Address(String address)
address
- the String that we'd like to determine as an IPv4 address.public static boolean isIPv6Address(String address)
address
- the String that we'd like to determine as an IPv6 address.public static boolean isValidIPAddress(String address)
address
- the address that we'd like to checkpublic static byte[] strToIPv4(String ipv4AddrStr)
ipv4AddrStr
- a String containing an IPv4 address.public static byte[] strToIPv6(String ipv6AddrStr)
ipv6AddrStr
- a String containing an IPv6 address.public static byte[] mappedIPv4ToRealIPv4(byte[] addr)
addr
- a String representing an IPv4-Mapped address in textual
formatprivate static boolean isMappedIPv4Addr(byte[] address)
address
- the address that we'd like to determine as an IPv4 mapped
one or not.public static InetAddress getInetAddress(String hostAddress) throws UnknownHostException
hostAddress
- the String representation of the address
that we would like to create an InetAddress instance for.UnknownHostException
- if any of the InetAddress methods
we are using throw an exception.private static String determineAnyAddress()
public static boolean isValidPortNumber(int port)
port
- the port number that we'd like verified.public static boolean isInterfaceLoopback(NetworkInterface iface)
iface
- the inteface that we'd like to determine as loopback or not.public static boolean isInterfaceUp(NetworkInterface iface)
NetworkInterface
's isUp() when running a JVM that
supports it and return a default value otherwise.iface
- the interface that we'd like to determine as Up or Down.public static boolean isInterfaceVirtual(NetworkInterface iface)
NetworkInterface
's
isVirtual() when running a JVM that supports it and return a
default value otherwise.iface
- the interface that we'd like to determine as virtual or not.public static String stripScopeID(String ipv6Address)
ipv6Address
- the address whose scope ID we'd like to get rid of.Copyright © 2018. All rights reserved.