public static boolean isIpAddressLocalhost(InetAddress addr) {
        if (addr == null) return false;

        // Check if the address is a valid special local or loop back
        if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
            return true;

        // Check if the address is defined on any interface
        try {
            return NetworkInterface.getByInetAddress(addr) != null;
        } catch (SocketException e) {
            return false;
        }
    }
Check if the provided ip address refers to the localhost

https://stackoverflow.com/a/2406819/315998

@param addr - address to check
@return - true if ip address is self
library/src/main/java/com/stealthcopter/networktools/IPTools.java