Here you can find the source of isValidAddress(InetAddress address, int timeoutMs)
Parameter | Description |
---|---|
address | The testing address |
timeoutMs | Timeout in milliseconds to use for checking that a possible local IP is reachable |
Parameter | Description |
---|---|
IOException | if the address resolution fails |
private static boolean isValidAddress(InetAddress address, int timeoutMs) throws IOException
//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); } }