List of utility methods to do IP Address to Int
long | ip2Int(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; |
int | ip2Int(String ip) ip Int return (int) ip2Long(ip); |
long | ip2int(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]); |
int | IP2Int(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; |
int | ip2int(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; |
int | ipToInt(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]); ... |
Long | ipToInt(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; |
int | ipToInt(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; |
int | ipToInt(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++) ; ... |
int | ipToInt(String ipAddr) ip To Int try { return bytesToInt(ipToBytesByInet(ipAddr)); } catch (Exception e) { throw new IllegalArgumentException(ipAddr + " is invalid IP"); |