Java IP Address to Long ipToLong(String strIP)

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

Description

ip To Long

License

Apache License

Declaration

private static long ipToLong(String strIP) 

Method Source Code

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

public class Main {
    private static long ipToLong(String strIP) {
        int j = 0;

        int i = 0;

        long[] ip = new long[4];

        int position1 = strIP.indexOf(".");

        int position2 = strIP.indexOf(".", position1 + 1);

        int position3 = strIP.indexOf(".", position2 + 1);

        ip[0] = Long.parseLong(strIP.substring(0, position1));

        ip[1] = Long.parseLong(strIP.substring(position1 + 1, position2));

        ip[2] = Long.parseLong(strIP.substring(position2 + 1, position3));

        ip[3] = Long.parseLong(strIP.substring(position3 + 1));

        return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];

    }//from w ww.j a v  a 2 s . co m
}

Related

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