Java Utililty Methods IP Address to Int

List of utility methods to do IP Address to Int

Description

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

Method

intIpToInt(String strIp)
Ip To Int
int[] ip = new int[4];
int position1 = strIp.indexOf(".");
int position2 = strIp.indexOf(".", position1 + 1);
int position3 = strIp.indexOf(".", position2 + 1);
ip[0] = Integer.parseInt(strIp.substring(0, position1));
ip[1] = Integer.parseInt(strIp.substring(position1 + 1, position2));
ip[2] = Integer.parseInt(strIp.substring(position2 + 1, position3));
ip[3] = Integer.parseInt(strIp.substring(position3 + 1));
...
intipToInteger(String ip)
ip To Integer
final String[] ipBytesStr = ip.split("\\.");
int ipValue = 0;
for (int i = 0; i < 4; i++) {
    ipValue <<= 8;
    ipValue |= Integer.parseInt(ipBytesStr[i]);
return ipValue;
intIPV4AddressStrToInteger(String ipAddressStr)
IPV Address Str To Integer
return IPV4AddressToInteger(textToNumericFormatV4(ipAddressStr));
intIPV4AddressToInteger(byte[] addr)
IPV Address To Integer
int hostAddress = addr[3] & 0xFF;
hostAddress |= ((addr[2] << 8) & 0xFF00);
hostAddress |= ((addr[1] << 16) & 0xFF0000);
hostAddress |= ((addr[0] << 24) & 0xFF000000);
return hostAddress;
intipV4ToInt(String addr)
ip V To Int
int[] ary = new int[4];
String[] strAry = addr.split("\\.");
for (int i = 0; i < 4; i++) {
    ary[i] = Integer.parseInt(strAry[i]);
int l = ary[0] << 24;
l += ary[1] << 16;
l += ary[2] << 8;
...
intipv4ToInt(String addr)
ipv To Int
Inet4Address a = (Inet4Address) InetAddress.getByName(addr);
byte[] b = a.getAddress();
int addrInt = ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16) | ((b[2] & 0xFF) << 8) | ((b[3] & 0xFF) << 0);
return addrInt;
intipv4ToInt(String address)
ipv To Int
String[] p = address.split("[.]");
return (Integer.parseInt(p[0]) << 24) | (Integer.parseInt(p[1]) << 16) | (Integer.parseInt(p[2]) << 8)
        | (Integer.parseInt(p[3]));