Here you can find the source of isPrivateIp(final InetAddress address)
Parameter | Description |
---|---|
address | address to test |
public static boolean isPrivateIp(final InetAddress address)
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Objects; public class Main { /**/*w ww. j av a2 s .c om*/ * Determines if a given IP address is private. * * @param ip IP address as {@link String} to test * @return true if private, otherwise false * @throws UnknownHostException thrown when the passed string can't be parsed for an IP */ public static boolean isPrivateIp(final String ip) throws UnknownHostException { final InetAddress address = InetAddress.getByName(ip); return isPrivateIp(address); } /** * Determines if a given IP address is private. * * @param address address to test * @return true if private, otherwise false */ public static boolean isPrivateIp(final InetAddress address) { Objects.requireNonNull("IP address must be present"); return address.isAnyLocalAddress() || address.isLoopbackAddress() || address.isLinkLocalAddress() || address.isSiteLocalAddress(); } }