Java InetAddress Check isPublic(InetAddress inetAddress)

Here you can find the source of isPublic(InetAddress inetAddress)

Description

is Public

License

Open Source License

Declaration

private static boolean isPublic(InetAddress inetAddress) 

Method Source Code

//package com.java2s;
/**/*from  w  ww  .  j  a v  a  2  s  .c  o  m*/
 * Aptana Studio
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
 * Please see the license.html included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */

import java.net.InetAddress;

public class Main {
    private static boolean isPublic(InetAddress inetAddress) {
        String hostAddress = inetAddress.getHostAddress();
        if (hostAddress.startsWith("10.") //$NON-NLS-1$
                || hostAddress.startsWith("192.168.") //$NON-NLS-1$
                || hostAddress.startsWith("169.254.") //$NON-NLS-1$
                || hostAddress.startsWith("127.")) { //$NON-NLS-1$
            return false;
        }
        if (hostAddress.startsWith("172.")) { //$NON-NLS-1$
            return !(inetAddress.getAddress()[1] >= 16 && inetAddress.getAddress()[1] <= 31);
        }
        return true;
    }
}

Related

  1. isPrivateIp(final InetAddress address)
  2. isPrivateIp(InetAddress addr)
  3. isPrivateIP(InetAddress ip)
  4. isPrivateNetworkAddress(final InetAddress inetAddress)
  5. isPrivateSubnet(InetAddress address)
  6. isPublicIp(InetAddress addr)
  7. isPublicIP4Address(InetAddress localAddress)
  8. isPubliclyRoutable(final InetAddress addrIP)
  9. isReachable(final InetAddress inetAddress, final int timeout)