Java IP Address to Int ip2Int(String addr)

Here you can find the source of ip2Int(String addr)

Description

ip Int

License

Open Source License

Parameter

Parameter Description
addr a parameter

Declaration

public static long ip2Int(String addr) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*ww w  . j  a  v  a 2s. co m*/
     * @param addr
     * @return
     */
    public static long ip2Int(String addr) {
        String[] addrArray = addr.split("\\.");
        long num = 0;
        for (int i = 0; i < addrArray.length; i++) {
            num += ((Integer.parseInt(addrArray[i]) % 256 * Math.pow(256,
                    3 - i)));
        }
        return num;
    }
}

Related

  1. ip2int(String ip)
  2. ip2Int(String ip)
  3. IP2Int(String ip)
  4. ip2int(String ipAddr)