Ejemplo n.º 1
0
  /**
   * Checks whether the repondent IP address is local by getting the complete list of local
   * addresses for all interfaces and looking for a match.
   *
   * @param ipAddress
   * @return true if the address is assigned to a local interface.
   */
  protected boolean responseIsLocal(String ipAddress) {
    String[] localAddresses;

    try {
      localAddresses = NetworkUtils.getLocalAddressStrings();

      if (localAddresses != null) {
        List<String> addressList = Arrays.asList(localAddresses);

        if (addressList.contains(ipAddress)) {
          return true;
        }
      }

    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SocketException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return false;
  }