Tuesday, 14 March 2017

Java program to get machine or local host IP address

import java.net.InetAddress;
import java.net.UnknownHostException;
 
public class MyIpAddress {
 
    public static void main(String a[]){
     
        try {
            InetAddress ipAddr = InetAddress.getLocalHost();
            System.out.println(ipAddr.getHostAddress());
        } catch (UnknownHostException ex) {
            ex.printStackTrace();
        }
    }
}

No comments:

Post a Comment