Java IP Address to Long ip2Long(String ipaddress)

Here you can find the source of ip2Long(String ipaddress)

Description

ip Long

License

LGPL

Declaration

public static long ip2Long(String ipaddress) 

Method Source Code

//package com.java2s;

public class Main {
    public static long ip2Long(String ipaddress) {

        long[] ip = new long[4];
        int position1 = ipaddress.indexOf(".");
        int position2 = ipaddress.indexOf(".", position1 + 1);
        int position3 = ipaddress.indexOf(".", position2 + 1);
        ip[0] = Long.parseLong(ipaddress.substring(0, position1));
        ip[1] = Long.parseLong(ipaddress.substring(position1 + 1, position2));
        ip[2] = Long.parseLong(ipaddress.substring(position2 + 1, position3));
        ip[3] = Long.parseLong(ipaddress.substring(position3 + 1));
        return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
    }// ww  w . ja  v  a 2s.  c  om
}

Related

  1. ip2long(String ip)
  2. ip2long(String ip)
  3. ip2long(String ip)
  4. ip2Long(String ip)
  5. ip2Long(String ipAddress)
  6. ipToLong(byte[] address)
  7. ipToLong(byte[] octets)
  8. ipToLong(final String addr)
  9. ipToLong(String addr)