Here you can find the source of ip2Long(String ip)
public static final long ip2Long(String ip)
//package com.java2s; //License from project: Open Source License public class Main { public static final long ip2Long(String ip) { if (ip == null) return 0; if (ip.startsWith("/")) ip = ip.substring(1);//from w w w. j a v a2s. c om int i = ip.indexOf(":"); if (i > 0) ip = ip.substring(0, i); String[] strs = ip.split("\\."); long longIp = 0; if (strs.length == 4) { for (i = 3; i >= 0; i--) { longIp += (Long.parseLong(strs[3 - i]) << (i * 8)); } } else if (strs.length == 6) { for (i = 5; i >= 0; i--) { longIp += (Long.parseLong(strs[5 - i]) << (i * 8)); } } return longIp; } }