Java IP Address to Long ip2long(String ip)

Here you can find the source of ip2long(String ip)

Description

string ip to long ip

License

Apache License

Parameter

Parameter Description
ip a parameter

Return

long

Declaration

public static long ip2long(String ip) 

Method Source Code

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

public class Main {
    /**//from  ww w . j a va2s .c o  m
     * string ip to long ip
     * 
     * @param    ip
     * @return    long
    */
    public static long ip2long(String 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);
    }
}

Related

  1. ip2long(String ip)
  2. ip2long(String ip)
  3. ip2Long(String ip)
  4. ip2long(String ip)
  5. ip2long(String ip)
  6. ip2Long(String ip)
  7. ip2Long(String ipAddress)
  8. ip2Long(String ipaddress)
  9. ipToLong(byte[] address)