Java IP Address to Int ipToInt(String ip)

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

Description

ip To Int

License

Apache License

Declaration

public static int ipToInt(String ip) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int ipToInt(String ip) {
        if (ip == null)
            return 0;
        char[] chars = ip.toCharArray();
        int i1, i2, i3;
        for (i1 = 0; i1 < chars.length && chars[i1] != '.'; i1++)
            ;//from  w  w w.ja  va2s  .co  m
        for (i2 = i1 + 1; i2 < chars.length && chars[i2] != '.'; i2++)
            ;
        for (i3 = i2 + 1; i3 < chars.length && chars[i3] != '.'; i3++)
            ;
        return (Integer.parseInt(ip.substring(0, i1), 10) << 24)
                | (Integer.parseInt(ip.substring(i1 + 1, i2), 10) << 16)
                | (Integer.parseInt(ip.substring(i2 + 1, i3), 10) << 8)
                | Integer.parseInt(ip.substring(i3 + 1, chars.length), 10);
    }
}

Related

  1. IP2Int(String ip)
  2. ip2int(String ipAddr)
  3. ipToInt(final String addr)
  4. ipToInt(String addr)
  5. ipToInt(String address)
  6. ipToInt(String ipAddr)
  7. IpToInt(String strIp)
  8. ipToInteger(String ip)
  9. IPV4AddressStrToInteger(String ipAddressStr)