Java InetAddress Check isValidAddress(InetAddress address, int timeoutMs)

Here you can find the source of isValidAddress(InetAddress address, int timeoutMs)

Description

Tests if the address is externally resolvable.

License

Apache License

Parameter

Parameter Description
address The testing address
timeoutMs Timeout in milliseconds to use for checking that a possible local IP is reachable

Exception

Parameter Description
IOException if the address resolution fails

Return

a boolean indicating if the given address is externally resolvable address

Declaration

private static boolean isValidAddress(InetAddress address, int timeoutMs) throws IOException 

Method Source Code


//package com.java2s;
/*//from  ww  w . j a  v  a2  s  . c o m
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

import java.io.IOException;

import java.net.Inet4Address;
import java.net.InetAddress;

public class Main {
    /**
     * Tests if the address is externally resolvable. Address must not be wildcard, link local,
     * loopback address, non-IPv4, or other unreachable addresses.
     *
     * @param address The testing address
     * @param timeoutMs Timeout in milliseconds to use for checking that a possible local IP is
     *        reachable
     * @return a {@code boolean} indicating if the given address is externally resolvable address
     * @throws IOException if the address resolution fails
     */
    private static boolean isValidAddress(InetAddress address, int timeoutMs) throws IOException {
        return !address.isAnyLocalAddress() && !address.isLinkLocalAddress() && !address.isLoopbackAddress()
                && address.isReachable(timeoutMs) && (address instanceof Inet4Address);
    }
}

Related

  1. isTenDot(InetAddress adr)
  2. isThisMyIpAddress(InetAddress addr)
  3. isThisMyIpAddress(InetAddress addr)
  4. isUDPPortFree(int port, InetAddress addr)
  5. isUnicastAddress(@CheckForNull InetAddress address)
  6. isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs)
  7. isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs)
  8. isValidCiscoWildcard(InetAddress wildcard)
  9. isValidInetAddress(String address)