Create IP address from byte array in Java
Description
The following code shows how to create IP address from byte array.
Example
import java.net.InetAddress;
/*from w w w.j a v a 2s . c o m*/
public class Main {
public static void main(String[] argv) throws Exception {
byte[] ipAddr = new byte[] {(byte) 173, (byte)194, 33, 115 };
InetAddress addr = InetAddress.getByAddress(ipAddr);
String hostnameCanonical = addr.getCanonicalHostName();
System.out.println(hostnameCanonical);
}
}
The code above generates the following result.