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

longip2Int(String addr)
ip Int
String[] addrArray = addr.split("\\.");
long num = 0;
for (int i = 0; i < addrArray.length; i++) {
    num += ((Integer.parseInt(addrArray[i]) % 256 * Math.pow(256, 3 - i)));
return num;
intip2Int(String ip)
ip Int
return (int) ip2Long(ip);
longip2int(String ip)
ipint
ip = ip.replace(".", ",");
String[] items = ip.split(",");
return Long.valueOf(items[0]) << 24 | Long.valueOf(items[1]) << 16 | Long.valueOf(items[2]) << 8
        | Long.valueOf(items[3]);
intIP2Int(String ip)
Converter IP to integer
String ipString = "";
int part;
String parts[] = ip.split("\\.");
for (int i = 0; i < parts.length; i++) {
    part = Integer.parseInt(parts[i]);
    parts[i] = Integer.toHexString(0x100 | part).substring(1);
    ipString = ipString + parts[i];
int ipInt = Integer.parseInt(ipString, 16);
return ipInt;
intip2int(String ipAddr)
ipint
byte[] bytes = ip2bytes(ipAddr);
int addr = bytes[3] & 0xFF;
addr |= ((bytes[2] << 8) & 0xFF00);
addr |= ((bytes[1] << 16) & 0xFF0000);
addr |= ((bytes[0] << 24) & 0xFF000000);
return addr;
intipToInt(final String addr)
Converts the text form of an IP address to an integer.
final String[] addressBytes = addr.split("\\.");
if (addressBytes.length != 4) {
    throw new IllegalArgumentException("IPs have the format x.x.x.x");
int ip = 0;
for (int i = 0; i < 4; i++) {
    ip <<= 8;
    ip |= Integer.parseInt(addressBytes[i]);
...
LongipToInt(String addr)
ip To Int
String[] addrArray = addr.split("\\.");
long num = 0;
for (int i = 0; i < addrArray.length; i++) {
    int power = 3 - i;
    num += ((Integer.parseInt(addrArray[i]) % 256 * Math.pow(256, power)));
return num;
intipToInt(String address)
ip To Int
String[] nibbles = address.split("\\.");
int result = Integer.parseInt(nibbles[0]) << 24;
result |= Integer.parseInt(nibbles[1]) << 16;
result |= Integer.parseInt(nibbles[2]) << 8;
result |= Integer.parseInt(nibbles[3]);
return result;
intipToInt(String ip)
ip To Int
if (ip == null)
    return 0;
char[] chars = ip.toCharArray();
int i1, i2, i3;
for (i1 = 0; i1 < chars.length && chars[i1] != '.'; i1++)
    ;
for (i2 = i1 + 1; i2 < chars.length && chars[i2] != '.'; i2++)
    ;
...
intipToInt(String ipAddr)
ip To Int
try {
    return bytesToInt(ipToBytesByInet(ipAddr));
} catch (Exception e) {
    throw new IllegalArgumentException(ipAddr + " is invalid IP");