Here you can find the source of ipToLong(String ipAddress)
public static Long ipToLong(String ipAddress)
//package com.java2s; //License from project: Open Source License public class Main { public static Long ipToLong(String ipAddress) { Long result = 0L;/* w w w .j a v a2s . c o m*/ String[] atoms = ipAddress.split("\\."); if (atoms.length != 4) { return null; } for (int i = 3; i >= 0; i--) { result |= (Long.parseLong(atoms[3 - i]) << (i * 8)); } return result & 0xFFFFFFFF; } public static Long parseLong(String val, Long defaultVal) { Long ret = defaultVal; if (val != null && val.length() > 0) { try { ret = Long.parseLong(val); } catch (NumberFormatException e) { } } return ret; } public static long parseLong(String val, long defaultVal) { long ret = defaultVal; if (val != null && val.length() > 0) { try { ret = Long.parseLong(val); } catch (NumberFormatException e) { } } return ret; } }