Here you can find the source of ipToLong(String ipAddress)
Parameter | Description |
---|---|
ipAddress | Input IP address |
public static long ipToLong(String ipAddress)
//package com.java2s; //License from project: Apache License public class Main { /**// www . j a v a 2 s. c o m * Convert an IP address to a number * * @param ipAddress Input IP address * * @return The IP address as a number */ public static long ipToLong(String ipAddress) { String[] atoms = ipAddress.split("\\."); long result = 0; for (int i = 3; i >= 0; i--) { result |= (Long.parseLong(atoms[3 - i]) << (i * 8)); } return result & 0xFFFFFFFF; } }