InetAddress GetByAddress1() Example
Create an InetAddress based on the provided host name and IP address
InetAddressclass GetByAddress1() method example. This example shows you how to use GetByAddress1() method.This method Create an InetAddress based on the provided host name and IP address
Here is the code:-
/*
* @Program that Create an InetAddress based on the provided host name and IP address
* GetByAddress1.java
* Author:-RoseIndia Team
* Date:-19-Jun-2008
*/
import java.net.*;
public class GetByAddress1 {
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("Roseindia",b);
System.out.println("InetAddress based on the provided host name and IP address is : "
+ob2);
}
} |
Output of the program:-
| InetAddress based on the provided host name and IP address is : Roseindia/127.2.8.24 |
|