News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

InetAddress GetByAddress1() Example

Started by VelMurugan, Jan 07, 2009, 04:01 PM

Previous topic - Next topic

VelMurugan

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

Source : codingdiary

VelMurugan

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

Source : codingdiary

nandagopal



This code shows some exception error !!!!