Java IP Address to Long ip2long(String ip)

Here you can find the source of ip2long(String ip)

Description

Convert dotted IP to long

License

Open Source License

Parameter

Parameter Description
ip a parameter

Return

long

Declaration

public static long ip2long(String ip) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from ww w .  java  2  s .c o  m
     * Convert dotted IP to long
     * 
     * @param ip
     * @return long
     */
    public static long ip2long(String ip) {
        String[] part = ip.split("\\.");
        long num = 0;
        for (int i = 0; i < part.length; i++) {
            int power = 3 - i;
            num += ((Integer.parseInt(part[i]) % 256 * Math.pow(256, power)));
        }
        return num;
    }
}

Related

  1. ip2long(String ip)
  2. ip2Long(String ip)
  3. ip2long(String ip)
  4. ip2long(String ip)
  5. ip2long(String ip)
  6. ip2long(String ip)
  7. ip2Long(String ip)
  8. ip2Long(String ipaddress)
  9. ip2Long(String ipAddress)