code: private boolean isLocalIpAddress(InetAddress addr) {
      if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
        return true;
      try {
        return NetworkInterface.getByInetAddress(addr) != null;
      } catch (SocketException e) {
        return false;
      }
    }
docs: Checks if the address is local.