Java IP Address to Int IP2Int(String ip)

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

Description

Converter IP to integer

License

Open Source License

Declaration

private static int IP2Int(String ip) 

Method Source Code

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

public class Main {
    /**/*  w w  w .  j a va2s.  c o m*/
     * Converter IP to integer
     */
    private static int IP2Int(String ip) {

        String ipString = "";
        int part;
        String parts[] = ip.split("\\.");
        for (int i = 0; i < parts.length; i++) {
            part = Integer.parseInt(parts[i]);
            parts[i] = Integer.toHexString(0x100 | part).substring(1);
            ipString = ipString + parts[i];
        }

        int ipInt = Integer.parseInt(ipString, 16);

        return ipInt;
    }
}

Related

  1. ip2Int(String addr)
  2. ip2int(String ip)
  3. ip2Int(String ip)
  4. ip2int(String ipAddr)
  5. ipToInt(final String addr)
  6. ipToInt(String addr)
  7. ipToInt(String address)