public String getIpAddress(boolean ipv6) {
		try {
			for (Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
					.getNetworkInterfaces(); networkInterfaces
					.hasMoreElements();) {
				NetworkInterface networkInterface = networkInterfaces
						.nextElement();
				for (Enumeration<InetAddress> addresses = networkInterface
						.getInetAddresses(); addresses.hasMoreElements();) {
					InetAddress inetAddress = addresses.nextElement();
					if (inetAddress.isLoopbackAddress()) {
						continue;
					}
					if (ipv6 && inetAddress instanceof Inet6Address) {

						return inetAddress.getHostAddress();
					} else if (ipv6 == false
							&& inetAddress instanceof Inet4Address) {
						return inetAddress.getHostAddress();
					}
				}
			}
		} catch (SocketException e) {
			throw new RuntimeException(e);
		}
		return null;
	}
public String getIpAddress ( boolean ipv6 ) { try { for ( Enumeration < NetworkInterface > networkInterfaces = NetworkInterface . getNetworkInterfaces ( ) ; networkInterfaces . hasMoreElements ( ) ; ) { NetworkInterface networkInterface = networkInterfaces . nextElement ( ) ; for ( Enumeration < InetAddress > addresses = networkInterface . getInetAddresses ( ) ; addresses . hasMoreElements ( ) ; ) { InetAddress inetAddress = addresses . nextElement ( ) ; if ( inetAddress . isLoopbackAddress ( ) ) { continue ; } if ( ipv6 && inetAddress instanceof Inet6Address ) { return inetAddress . getHostAddress ( ) ; } else if ( ipv6 == false && inetAddress instanceof Inet4Address ) { return inetAddress . getHostAddress ( ) ; } } } } catch ( SocketException e ) { throw new RuntimeException ( e ) ; } return null ; }
Returns IP Address<br>
Requires READ_PHONE_STATE, ACCESS_WIFI_STATE and INTERNET permissions<br>

@param ipv6
Option to choose IP address type
@return IP address made up of IPv6 if parameter ipv6 is true or IPv4 if
parameter ipv6 is false; null if it do not have IP address
@throws RuntimeException
when it fails due to poor network condition