public static long ipToLong(Inet4Address ip){
  byte[] octets=ip.getAddress();
  long result=0;
  for (  byte octet : octets) {
    result<<=8;
    result|=octet & 0xff;
  }
  return result;
}

public static long ipToLong ( Inet4Address ip ) { byte [ ] octets = ip . getAddress ( ) ; long result = 0 ; for ( byte octet : octets ) { result <<= 8 ; result |= octet & 0xff ; } return result ; }
convert an inet4address to host byte order long .
