Java IP Address to Long ip2Long(final String ip)

Here you can find the source of ip2Long(final String ip)

Description

ip Long

License

Apache License

Declaration

public static long ip2Long(final String ip) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

public class Main {
    public static long ip2Long(final String ip) {
        final String[] tokens = ip.split("[.]");
        assert tokens.length == 4;
        long result = 0;
        for (int i = 0; i < tokens.length; i++) {
            try {
                result = result << 8 | Integer.parseInt(tokens[i]);
            } catch (final NumberFormatException e) {
                throw new RuntimeException("Incorrect number", e);
            }/*w w  w.  j a  va 2  s.c  o m*/
        }

        return result;
    }
}

Related

  1. convertIPS2Long(String ip)
  2. convertIpString2Long(String IP)
  3. ip2long(String ip)
  4. ip2long(String ip)
  5. ip2long(String ip)
  6. ip2Long(String ip)