Java IP Address to Long ipToLong(String ipAddress)

Here you can find the source of ipToLong(String ipAddress)

Description

Convert an IP address to a number

License

Apache License

Parameter

Parameter Description
ipAddress Input IP address

Return

The IP address as a number

Declaration

public static long ipToLong(String ipAddress) 

Method Source Code

//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;
    }
}

Related

  1. ipToLong(String ip)
  2. ipToLong(String ip)
  3. ipToLong(String ip)
  4. ipToLong(String ip)
  5. ipToLong(String ip)
  6. ipToLong(String ipAddress)
  7. ipToLong(String ipStr)
  8. ipToLong(String sip)
  9. ipToLong(String strIP)