Java Utililty Methods InetAddress Check

List of utility methods to do InetAddress Check

Description

The list of methods to do InetAddress Check are organized into topic(s).

Method

booleanisPubliclyRoutable(final InetAddress addrIP)
Determines whether a particular IP address is publicly routable on the internet
if (addrIP == null)
    throw new NullPointerException("isPubliclyRoutable requires an IP address be passed to it!");
return !addrIP.isSiteLocalAddress() && !addrIP.isLinkLocalAddress() && !addrIP.isLoopbackAddress();
booleanisReachable(final InetAddress inetAddress, final int timeout)
is Reachable
return inetAddress.isReachable(timeout);
booleanisReachable(InetAddress address, int port)
is Reachable
return isReachable(address, Arrays.asList(port));
booleanisReachable(NetworkInterface iface, InetAddress address, int timeout)
is Reachable
try {
    return address.isReachable(iface, 0, timeout);
} catch (IOException e) {
    return false;
booleanisReservedAddr(InetAddress inetAddr)
Check if it's "local address" or "link local address" or "loopbackaddress"
if (inetAddr.isAnyLocalAddress() || inetAddr.isLinkLocalAddress() || inetAddr.isLoopbackAddress()) {
    return true;
return false;
booleanisServerAlive(InetAddress host, int port)
Check whether a server is alive.
Socket socket = null;
int i = 0;
while (i < RETRY_COUNT) {
    try {
        socket = new Socket(host, port);
        break;
    } catch (IOException e) {
        i++;
...
booleanisServerAlive(InetAddress host, int port)
Check whether a server is alive.
Socket socket = null;
int i = 0;
while (i < RETRY_COUNT) {
    try {
        socket = new Socket(host, port);
        break;
    } catch (IOException e) {
        i++;
...
booleanisSiteLocalAddress(InetAddress i)
Check if address is in site-local range.
if (i instanceof Inet6Address) {
    byte[] addr = i.getAddress();
    assert (addr.length == 128 / 8);
    return ((addr[0] & (byte) 0xfe) == (byte) 0xfc
    ) || (addr[0] == (byte) 0xfe && (addr[1] & (byte) 0xc0) == (byte) 0xc0
    );
return i.isSiteLocalAddress();
...
booleanisTenDot(InetAddress adr)
is Ten Dot
return getOneDotPrefix(adr).equals("10");
booleanisThisMyIpAddress(InetAddress addr)
Check if the given address is pointing to this local machine.
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) {
    return true;
try {
    return NetworkInterface.getByInetAddress(addr) != null;
} catch (SocketException ex) {
    return false;