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; /*/*from w w w . ja va 2 s . c o m*/ * Copyright 2017 AT&T * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.net.UnknownHostException; public class Main { private static final int IPV4_ADDRESS_LEN = 4; /** * 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; } }