Here you can find the source of ipToInt(String ipAddr)
public static int ipToInt(String ipAddr)
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; public class Main { public static int ipToInt(String ipAddr) { try {/*from w w w . j av a2s. c o m*/ return bytesToInt(ipToBytesByInet(ipAddr)); } catch (Exception e) { throw new IllegalArgumentException(ipAddr + " is invalid IP"); } } public static int bytesToInt(byte[] bytes) { int addr = bytes[3] & 0xFF; addr |= ((bytes[2] << 8) & 0xFF00); addr |= ((bytes[1] << 16) & 0xFF0000); addr |= ((bytes[0] << 24) & 0xFF000000); return addr; } public static byte[] ipToBytesByInet(String ipAddr) { try { return InetAddress.getByName(ipAddr).getAddress(); } catch (Exception e) { throw new IllegalArgumentException(ipAddr + " is invalid IP"); } } }