InetAddress GetByAddress() Example
Returns an InetAddress object given the raw IP address .
InetAddressclass GetByAddress() method example. This example shows you how to use GetByAddress() method.This method Returns an InetAddress object given the raw IP address .
Here is the code:-
/*
* @Program that Returns an InetAddress object given the raw IP address .
* GetByAddress.java
* Author:-RoseIndia Team
* Date:-19-Jun-2008
*/
import java.net.*;
public class GetByAddress {
public static void main(String[] args) throws UnknownHostException {
byte[] b = new byte[4];
InetAddress ob1 = InetAddress.getByName("girish-desktop");
b[ 0] = new Integer(127).byteValue();
b[ 1] = new Integer(2).byteValue();
b[ 2] = new Integer(8).byteValue();
b[ 3] = new Integer(24).byteValue();
//Returns an InetAddress object given the raw IP address .
InetAddress ob2 = InetAddress.getByAddress(b);
System.out.println("InetAddress of object is : "+ob2);
}
} |
Output of the program:-
InetAddress of object is : /127.2.8.24
|
|