Java InetAddress Create getInetAddressFromAsciiIP(String ip)

Here you can find the source of getInetAddressFromAsciiIP(String ip)

Description

Given an ASCII format IP address string, return an InetAddress object.

License

Open Source License

Parameter

Parameter Description
ip a parameter

Exception

Parameter Description
UnknownHostException an exception

Return

inetAddress object

Declaration

public static InetAddress getInetAddressFromAsciiIP(String ip) throws UnknownHostException 

Method Source Code

//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);
    }
}

Related

  1. getInetAddress(String str)
  2. getInetAddressByName(String name)
  3. getInetAddresses()
  4. getInetAddresses(String filter)
  5. getInetAddressFor(final Inet6Address inetAddress, String scope)
  6. getInetAddressFromConfigString( String fixedDeviceConfigSring)
  7. getInetAddressFromString(String s)
  8. getInetAddressMap()
  9. getInetAddressMap()