Creating InetAddress object in Java

You should be able to use getByName or getByAddress.

The host name can either be a machine
name, such as “java.sun.com”, or a
textual representation of its IP
address

InetAddress addr = InetAddress.getByName("127.0.0.1");

The method that takes a byte array can be used like this:

byte[] ipAddr = new byte[]{127, 0, 0, 1};
InetAddress addr = InetAddress.getByAddress(ipAddr);

Leave a Comment