Here you can find the source of toLong(InetAddress ip)
public static long toLong(InetAddress ip)
//package com.java2s; //License from project: Creative Commons License import java.net.InetAddress; public class Main { public static long toLong(String ip) { String[] addressArray = ip.split("\\."); long result = 0; for (int i = 0; i < addressArray.length; i++) { int power = 3 - i; result += ((Integer.parseInt(addressArray[i]) % 256 * Math.pow(256, power))); }//from w w w . ja v a2s. c o m return result; } public static long toLong(InetAddress ip) { return toLong(getIP(ip)); } public static String getIP(InetAddress ip) { return ip.getHostAddress().replace("/", ""); } }