Here you can find the source of ipTolong(String address)
Parameter | Description |
---|---|
address | IP Address that to be converted to long |
private static long ipTolong(String address)
//package com.java2s; /*//from w w w .j a va 2 s . c om * Copyright ? 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Get IP Address in Long from String. * * @param address IP Address that to be converted to long * @return Long value of the IP Address */ private static long ipTolong(String address) { // Parse IP parts into an int array long[] ip = new long[4]; String[] parts = address.split("\\."); for (int i = 0; i < 4; i++) { ip[i] = Long.parseLong(parts[i]); } // Add the above IP parts into an int number representing your IP // in a 32-bit binary form long ipNumbers = 0; for (int i = 0; i < 4; i++) { ipNumbers += ip[i] << (24 - (8 * i)); } return ipNumbers; } }