Java Utililty Methods IP Address to Long

List of utility methods to do IP Address to Long

Description

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

Method

longconvertIPS2Long(String ip)
convert IPS Long
char[] c = ip.toCharArray();
byte[] b = { 0, 0, 0, 0 };
for (int i = 0, j = 0; i < c.length;) {
    int d = (byte) (c[i] - '0');
    switch (c[i++]) {
    case '.':
        ++j;
        break;
...
longconvertIpString2Long(String IP)
Parse the long number of IPv4 address from dot-separated string
String[] addrArray = IP.split("\\.");
if (addrArray.length != 4) {
    throw new NumberFormatException("Invalid IP string format: " + IP);
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)));
...
longip2Long(final String ip)
ip Long
final String[] tokens = ip.split("[.]");
assert tokens.length == 4;
long result = 0;
for (int i = 0; i < tokens.length; i++) {
    try {
        result = result << 8 | Integer.parseInt(tokens[i]);
    } catch (final NumberFormatException e) {
        throw new RuntimeException("Incorrect number", e);
...
longip2long(String ip)
iplong
String[] ips = ip.split("[.]");
long num = 16777216L * Long.parseLong(ips[0]) + 65536L * Long.parseLong(ips[1])
        + 256 * Long.parseLong(ips[2]) + Long.parseLong(ips[3]);
return num;
longip2long(String ip)
iplong
String[] parts = ip.split("\\.");
long result = 0;
int power = 0;
if (parts.length != 4) {
    throw new IllegalArgumentException("Invalid IP format");
for (int i = parts.length; i > 0; i--) {
    int parseInt = Integer.parseInt(parts[i - 1]);
...
Longip2long(String ip)
iplong
String[] arrStr = ip.split("\\.");
if (arrStr.length != 4)
    throw new IllegalArgumentException("Wrong IP address");
Long longIP = Long.parseLong(arrStr[0]) * 256 * 256 * 256 + Long.parseLong(arrStr[1]) * 256 * 256
        + Long.parseLong(arrStr[2]) * 256 + Long.parseLong(arrStr[3]);
return longIP;
longip2Long(String ip)
ip Long
if (ip == null)
    return 0;
if (ip.startsWith("/"))
    ip = ip.substring(1);
int i = ip.indexOf(":");
if (i > 0)
    ip = ip.substring(0, i);
String[] strs = ip.split("\\.");
...
longip2long(String ip)
iplong
long ipNumber = 0;
String[] ips = ip.split("[.]");
for (int i = 0; i < 4; ++i) {
    ipNumber = ipNumber << 8 | Integer.parseInt(ips[i]);
return ipNumber;
longip2long(String ip)
Convert dotted IP to long
String[] part = ip.split("\\.");
long num = 0;
for (int i = 0; i < part.length; i++) {
    int power = 3 - i;
    num += ((Integer.parseInt(part[i]) % 256 * Math.pow(256, power)));
return num;
longip2long(String ip)
string ip to long ip
String[] p = ip.split("\\.");
if (p.length != 4)
    return 0;
int p1 = ((Integer.valueOf(p[0]) << 24) & 0xFF000000);
int p2 = ((Integer.valueOf(p[1]) << 16) & 0x00FF0000);
int p3 = ((Integer.valueOf(p[2]) << 8) & 0x0000FF00);
int p4 = ((Integer.valueOf(p[3]) << 0) & 0x000000FF);
return ((p1 | p2 | p3 | p4) & 0xFFFFFFFFL);
...