Here you can find the source of ip2long(String ip)
public static long ip2long(String ip) throws NumberFormatException, IllegalArgumentException
//package com.java2s; //License from project: Open Source License public class Main { public static long ip2long(String ip) throws NumberFormatException, IllegalArgumentException { String[] parts = ip.split("\\."); long result = 0; int power = 0; if (parts.length != 4) { throw new IllegalArgumentException("Invalid IP format"); }/*w w w. j a v a 2s. c o m*/ for (int i = parts.length; i > 0; i--) { int parseInt = Integer.parseInt(parts[i - 1]); if (parseInt < 0 || parseInt > 255) { throw new IllegalArgumentException("Invalid IP address"); } result += Math.pow(256, power++) * parseInt; } return result; } }