Java IP Address to Long ipToLong(String sip)

Here you can find the source of ipToLong(String sip)

Description

ip To Long

License

Apache License

Declaration

public static long ipToLong(String sip) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static long ipToLong(String sip) {
        long[] ip = new long[4];
        int[] pos = new int[3];
        pos[0] = sip.indexOf(".");
        ip[0] = Long.parseLong(sip.substring(0, pos[0]));
        for (int i = 1; i < 3; i++) {
            pos[i] = sip.indexOf(".", pos[i - 1] + 1);
            ip[i] = Long.parseLong(sip.substring(pos[i - 1] + 1, pos[i]));
            if (i == 2) {
                ip[i + 1] = Long.parseLong(sip.substring(pos[i] + 1));
            }/*from   w  w  w . jav  a2s.c om*/
        }
        return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
    }
}

Related

  1. ipToLong(String ip)
  2. ipToLong(String ip)
  3. ipToLong(String ipAddress)
  4. ipToLong(String ipAddress)
  5. ipToLong(String ipStr)
  6. ipToLong(String strIP)
  7. ipv4(long ip)
  8. ipV4AddressToLong(String ipAddress)
  9. ipv4CidrToLong(String networkCidr)