InetAddress GetHostAddress() Example
Returns the IP address string in textual presentation.
InetAddressclass GetHostAddress() method example. This example shows you how to use GetHostAddress() method.This method Returns the IP address string in textual presentation.
Here is the code:-
/*
* @Program that Returns the IP address string in textual presentation.
* GetHostAddress.java
* Author:-RoseIndia Team
* Date:-19-Jun-2008
*/
import java.net.*;
public class GetHostAddress {
public static void main(String[] args) throws UnknownHostException {
InetAddress ia = InetAddress.getLocalHost();
//Returns the IP address string in textual presentation.
String s=ia.getHostAddress();
System.out.println("IP address is : "+s);
}
} |
Output of the program:-
| IP address is : 127.0.1.1 |
|