Java IP Address to Long ipV4ToLong(final String ipAddress)

Here you can find the source of ipV4ToLong(final String ipAddress)

Description

ip V To Long

License

Open Source License

Declaration

public static final long ipV4ToLong(final String ipAddress) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 BowenCai./*w w w . java2  s  .c  om*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     BowenCai - initial API and implementation
 ******************************************************************************/

public class Main {
    public static final long ipV4ToLong(final String ipAddress) {
        long result = 0;
        String[] atoms = ipAddress.split("\\.");

        for (int i = 3; i >= 0; i--) {
            result |= (Long.parseLong(atoms[3 - i]) << (i * 8));
        }
        return result & 0xFFFFFFFF;
    }
}

Related

  1. ipToLong(String sip)
  2. ipToLong(String strIP)
  3. ipv4(long ip)
  4. ipV4AddressToLong(String ipAddress)
  5. ipv4CidrToLong(String networkCidr)
  6. ipv4ToLong(final String ipv4)
  7. ipV4ToLong(String ip)