Monday, January 20, 2014

Java program to find IP Address of localhost


import java.net.UnknownHostException;

/**
 * Simple Java program to find IP Address of localhost. This program uses
 * InetAddress from java.net package to find IP address. 
 *
 * @author Javin Paul
 */
public class IPTest {
  
    public static void main(String args[]) throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        String ipAddress = addr.getHostAddress();
        System.out.println("IP address of localhost: " + ipAddress);
        String hostname = addr.getHostName();
        System.out.println("Name of hostname : " + hostname);
    }
}

Output:
IP address of localhost from Java Program: 190.12.209.123
Name of hostname : PCLOND3433

Source: http://javarevisited.blogspot.in/2012/09/java-program-to-find-ip-address-of.html

No comments:

Post a Comment