public static long convertIpToLong(String addr) {
	String[] addrArray = addr.split("\\.");
	long num = 0;
	for (int i = 0; i < addrArray.length; i++) {
		int power = 3 - i;
		num += ((Integer.parseInt(addrArray[i]) % 256 * Math.pow(256, power)));
	}
	return num;
}


Back to JavaHowTo

Alumni Liaison

Followed her dream after having raised her family.

Ruth Enoch, PhD Mathematics