Here you can find the source of ipToLong(String ip)
Parameter | Description |
---|---|
ip | the IP address to convert |
public static long ipToLong(String ip)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww . j av a2s .c om*/ * Converts a String IP address to a long. * * @param ip the IP address to convert * @return a long representation of the IP address */ public static long ipToLong(String ip) { String[] ipArray = ip.split("\\."); long num = 0; for (int i = 0; i < ipArray.length; i++) { int power = 3 - i; num += ((Integer.parseInt(ipArray[i]) % 256 * Math.pow(256, power))); } return num; } }