Android Utililty Methods IP Address Get

List of utility methods to do IP Address Get

Description

The list of methods to do IP Address Get are organized into topic(s).

Method

StringgetDevicesIP(Context context)
get Devices IP
WifiManager wifiManager = (WifiManager) context
        .getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) {
    wifiManager.setWifiEnabled(true);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = (ipAddress & 0xFF) + "." + ((ipAddress >> 8) & 0xFF)
...
StringgetIPs()
get I Ps
String ipaddress = "";
try {
    for (Enumeration<NetworkInterface> en = NetworkInterface
            .getNetworkInterfaces(); en.hasMoreElements();) {
        NetworkInterface intf = en.nextElement();
        for (Enumeration<InetAddress> enumIpAddr = intf
                .getInetAddresses(); enumIpAddr.hasMoreElements();) {
            InetAddress inetAddress = enumIpAddr.nextElement();
...
StringgetIPv4StringByStrippingIPv6Prefix(String in)
get I Pv String By Stripping I Pv Prefix
String ipv6Prefix = "::ffff:";
if (in.startsWith(ipv6Prefix)) {
    return in.substring(ipv6Prefix.length(), in.length());
return in;
byte[]getIPV4NetwprkOrder(String theIp)
turn ip in string representation to byte array in network order.
byte[] toReturn = new byte[IPV4_ADDRESS_LEN];
String[] fields = theIp.split("\\.");
if (fields == null || fields.length < IPV4_ADDRESS_LEN)
    throw new UnknownHostException();
for (int i = 0; i < fields.length; i++) {
    toReturn[i] = (byte) Integer.parseInt(fields[i]);
return toReturn;
...