Here you can find the source of getIPV4NetwprkOrder(String theIp)
Parameter | Description |
---|---|
theIp | a parameter |
Parameter | Description |
---|---|
UnknownHostException | an exception |
public static byte[] getIPV4NetwprkOrder(String theIp) throws UnknownHostException
//package com.java2s; import java.net.UnknownHostException; public class Main { private static final int IPV4_ADDRESS_LEN = 4; /**/*from w ww .j ava2s . c o m*/ * turn ip in string representation to byte array in network order. * @param theIp * @return ip as byte array * @throws UnknownHostException */ public static byte[] getIPV4NetwprkOrder(String theIp) throws UnknownHostException { byte[] toReturn = new byte[IPV4_ADDRESS_LEN]; String[] fields = theIp.split("\\."); if (fields == null || fields.length < IPV4_ADDRESS_LEN) throw new UnknownHostException(); for (int i = 0; i < fields.length; i++) { toReturn[i] = (byte) Integer.parseInt(fields[i]); } return toReturn; } }