Convert ip address in Int To String - Android java.net

Android examples for java.net:IP Address

Description

Convert ip address in Int To String

Demo Code

import java.net.Inet4Address;

public class Main{


    private static String ipIntToString(int ip) {
        try {//w  w w  .  ja v  a 2  s . c om
            byte[] bytes = new byte[4];
            bytes[0] = (byte) (0xff & ip);
            bytes[1] = (byte) ((0xff00 & ip) >> 8);
            bytes[2] = (byte) ((0xff0000 & ip) >> 16);
            bytes[3] = (byte) ((0xff000000 & ip) >> 24);
            return Inet4Address.getByAddress(bytes).getHostAddress();
        } catch (Exception e) {
            return "";
        }
    }

}

Related Tutorials