Here you can find the source of ip2long(String ip)
Parameter | Description |
---|---|
ip | a parameter |
public static long ip2long(String ip)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w . java 2 s .c o m * Convert dotted IP to long * * @param ip * @return long */ public static long ip2long(String ip) { String[] part = ip.split("\\."); long num = 0; for (int i = 0; i < part.length; i++) { int power = 3 - i; num += ((Integer.parseInt(part[i]) % 256 * Math.pow(256, power))); } return num; } }