Here you can find the source of ip2Int(String ip)
public static final int ip2Int(String ip)
//package com.java2s; //License from project: Open Source License public class Main { public static final int ip2Int(String ip) { return (int) ip2Long(ip); }//from www . j a v a 2s . c o m public static final long ip2Long(String ip) { 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("\\."); 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; } }