Here you can find the source of ipv4ToInt(String addr)
public static int ipv4ToInt(String addr) throws UnknownHostException
//package com.java2s; /*/*from ww w . j a v a 2 s . co m*/ * Copyright (c) 2015 Yale University and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static int ipv4ToInt(String addr) throws UnknownHostException { Inet4Address a = (Inet4Address) InetAddress.getByName(addr); byte[] b = a.getAddress(); int addrInt = ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16) | ((b[2] & 0xFF) << 8) | ((b[3] & 0xFF) << 0); return addrInt; } }