Here you can find the source of getInetAddressFromAsciiIP(String ip)
Parameter | Description |
---|---|
ip | a parameter |
Parameter | Description |
---|---|
UnknownHostException | an exception |
public static InetAddress getInetAddressFromAsciiIP(String ip) throws UnknownHostException
//package com.java2s; import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /**//from w w w. j a v a2s. c o m * Given an ASCII format IP address string, return an InetAddress object. * @param ip * @return inetAddress object * @throws UnknownHostException */ public static InetAddress getInetAddressFromAsciiIP(String ip) throws UnknownHostException { String[] ipComponents = ip.split("\\."); byte[] ipBytes = { (byte) Integer.parseInt(ipComponents[0]), (byte) Integer.parseInt(ipComponents[1]), (byte) Integer.parseInt(ipComponents[2]), (byte) Integer.parseInt(ipComponents[3]) }; return InetAddress.getByAddress(ipBytes); } }