Here you can find the source of ipV4ToLong(final String ipaddress)
Parameter | Description |
---|---|
ipaddress | a parameter |
Parameter | Description |
---|---|
UnknownHostException | an exception |
SecurityException | an exception |
public static long ipV4ToLong(final String ipaddress) throws UnknownHostException, SecurityException
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /*********************************************************************************************** * Convert an IP Address to a long./* w w w . j a v a2 s .c o m*/ * * @param ipaddress * * @return long * * @throws UnknownHostException * @throws SecurityException */ public static long ipV4ToLong(final String ipaddress) throws UnknownHostException, SecurityException { final String SOURCE = "NetworkScannerHelper.ipV4ToLong() "; final byte[] arrayBytes; final int octet1; final int octet2; final int octet3; final int octet4; long longAddress; //LOGGER.logTimedEvent(SOURCE + "String [address=" + ipaddress + "]"); arrayBytes = InetAddress.getByName(ipaddress).getAddress(); //LOGGER.logTimedEvent(SOURCE + "Bytes [address=" + Utilities.byteArrayToSpacedHex(arrayBytes) + "]"); octet1 = (arrayBytes[0] & 0xFF) << 24; octet2 = (arrayBytes[1] & 0xFF) << 16; octet3 = (arrayBytes[2] & 0xFF) << 8; octet4 = arrayBytes[3] & 0xFF; longAddress = octet1 | octet2 | octet3 | octet4; longAddress = longAddress & 0x00000000FFFFFFFFL; //LOGGER.logTimedEvent(SOURCE + "Long [address=" + longAddress + "]"); return (longAddress); } }