Inet4Address GetHostAddress() Example

returns the raw IP address in a string format.


Inet4Addressclass GetHostAddress() method example. This example shows you how to use GetHostAddress() method.This method returns the raw IP address in a string format.

Here is the code:-
/* 
 * @Program that returns the raw IP address in a string format..
 * GetHostAddress.java 
 * Author:-RoseIndia Team
 * Date:-28-Jun-2008
 */

import java.net.*;
import java.util.*;

public class GetHostAddress {

    public static void main(String[] argsthrows Exception {
        InetAddress i = Inet4Address.getByName("localhost");
        //returns the raw IP address in a string format..
        String s = i.getHostAddress();
        System.out.println("IP address in a string format: " + s);

    }
}

Output of the program:-
 IP address in a string format: 127.0.0.1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US