private String getLocalAddressOfType(Class<? extends InetAddress> cl) {
    try {
      String overrideIP = System.getProperty(OVERRIDE_LOCAL_IP);
      if (overrideIP != null && overrideIP.trim().length() > 0) {
        return overrideIP.trim();
      }
      Enumeration<NetworkInterface> interfaces = NetworkInterface
          .getNetworkInterfaces();
      while (interfaces.hasMoreElements()) {
        NetworkInterface current = interfaces.nextElement();
        if (!current.isUp() || current.isLoopback() || current.isVirtual()) {
          continue;
        }
        Enumeration<InetAddress> addresses = current.getInetAddresses();
        while (addresses.hasMoreElements()) {
          InetAddress adr = addresses.nextElement();
          if (cl.isInstance(adr)) {
            log.log(Level.FINER, "Local address resolved to {0}", adr);
            return adr.getHostAddress();
          }
        }
      }
      return "";
    } catch (IOException e) {
      log.log(Level.FINE, "Local address not resolvable.");
      return "";
    }
  }
private String getLocalAddressOfType(Class<? extends InetAddress> cl) {
    try {
      String overrideIP = System.getProperty(OVERRIDE_LOCAL_IP);
      if (overrideIP != null && overrideIP.trim().length() > 0) {
        return overrideIP.trim();
      }
      Enumeration<NetworkInterface> interfaces = NetworkInterface
          .getNetworkInterfaces();
      while (interfaces.hasMoreElements()) {
        NetworkInterface current = interfaces.nextElement();
        if (!current.isUp() || current.isLoopback() || current.isVirtual()) {
          continue;
        }
        Enumeration<InetAddress> addresses = current.getInetAddresses();
        while (addresses.hasMoreElements()) {
          InetAddress adr = addresses.nextElement();
          if (cl.isInstance(adr)) {
            log.log(Level.FINER, "Local address resolved to {0}", adr);
            return adr.getHostAddress();
          }
        }
      }
      return "";
    } catch (IOException e) {
      log.log(Level.FINE, "Local address not resolvable.");
      return "";
    }
  }
private String getLocalAddressOfType ( Class < ? extends InetAddress > cl ) { try { String overrideIP = System . getProperty ( OVERRIDE_LOCAL_IP ) ; if ( overrideIP != null && overrideIP . trim ( ) . length ( ) > 0 ) { return overrideIP . trim ( ) ; } Enumeration < NetworkInterface > interfaces = NetworkInterface . getNetworkInterfaces ( ) ; while ( interfaces . hasMoreElements ( ) ) { NetworkInterface current = interfaces . nextElement ( ) ; if ( ! current . isUp ( ) || current . isLoopback ( ) || current . isVirtual ( ) ) { continue ; } Enumeration < InetAddress > addresses = current . getInetAddresses ( ) ; while ( addresses . hasMoreElements ( ) ) { InetAddress adr = addresses . nextElement ( ) ; if ( cl . isInstance ( adr ) ) { log . log ( Level . FINER , "Local address resolved to {0}" , adr ) ; return adr . getHostAddress ( ) ; } } } return "" ; } catch ( IOException e ) { log . log ( Level . FINE , "Local address not resolvable." ) ; return "" ; } }
***********************************************************************
Get the current IP address of the computer. This will return the first
address of the first network interface that is a "real" IP address of the
given type.

@param cl
the type of address we are searching for.
@return the address as string or "" if not found.
**********************************************************************
*********************************************************************** Get the current IP address of the computer . This will return the first address of the first network interface that is a real IP address of the given type .