code: public static String[] getIPs(String strInterface)
      throws UnknownHostException {
      try {
        boolean toGetIpv4 = true;
        if (System.getProperty(PREFER_IPV6_ADDRESS_PROPERTY) != null) {
          toGetIpv4 = "false".equals(System
              .getProperty(PREFER_IPV6_ADDRESS_PROPERTY));
        }
        NetworkInterface netIF = NetworkInterface.getByName(strInterface);
        if (netIF == null) {
          return new String[] { InetAddress.getLocalHost()
                                .getHostAddress() };
        } else {
          Vector<String> ips = new Vector<String>();
          Enumeration<InetAddress> e = netIF.getInetAddresses();
          while (e.hasMoreElements()) {
            InetAddress curr = e.nextElement();
            if (toGetIpv4 && !(curr instanceof Inet4Address)) {
              continue;
            }
            ips.add(curr.getHostAddress());
          }
          return ips.toArray(new String[] {});
        }
      } catch (SocketException e) {
        return new String[] { InetAddress.getLocalHost().getHostAddress() };
      }
    }
docs: Returns all the IPs associated with the provided interface, if any, in
  textual form.
  
  @param strInterface
  The name of the network interface to query (e.g. eth0)
  @return A string vector of all the IPs associated with the provided
  interface
  @throws UnknownHostException
  If an UnknownHostException is encountered in querying the
  default interface