Java IP Address to Int IpToInt(String strIp)

Here you can find the source of IpToInt(String strIp)

Description

Ip To Int

License

Apache License

Declaration

public static int IpToInt(String strIp) 

Method Source Code

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

public class Main {
    public static int IpToInt(String strIp) {
        int[] ip = new int[4];
        int position1 = strIp.indexOf(".");
        int position2 = strIp.indexOf(".", position1 + 1);
        int position3 = strIp.indexOf(".", position2 + 1);

        ip[0] = Integer.parseInt(strIp.substring(0, position1));
        ip[1] = Integer.parseInt(strIp.substring(position1 + 1, position2));
        ip[2] = Integer.parseInt(strIp.substring(position2 + 1, position3));
        ip[3] = Integer.parseInt(strIp.substring(position3 + 1));
        return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
    }// w  ww  . ja va2  s .c  om
}

Related

  1. ipToInt(final String addr)
  2. ipToInt(String addr)
  3. ipToInt(String address)
  4. ipToInt(String ip)
  5. ipToInt(String ipAddr)
  6. ipToInteger(String ip)
  7. IPV4AddressStrToInteger(String ipAddressStr)
  8. IPV4AddressToInteger(byte[] addr)
  9. ipV4ToInt(String addr)