Here you can find the source of ipToLong(String ip)
public static long ipToLong(String ip) throws UnknownHostException
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static long ipToLong(String ip) throws UnknownHostException { byte[] address = InetAddress.getByName(ip).getAddress(); long ipnum = 0; for (int i = 0; i < 4; ++i) { long y = address[i]; if (y < 0) { y += 256;//www.j a v a 2s . c o m } ipnum += y << ((3 - i) * 8); } return ipnum; } }