Get ip address in java

The java.net.InetAddress class represents an IP address. It provides the methods to work with IP and host name.

Get ip address in java

package com.w3spoint;
 
import java.net.InetAddress;
 
public class NetworkTest {
  public static void main(String args[]){
	try {
	    InetAddress inetAddress = InetAddress.getLocalHost();
            System.out.println(inetAddress.getHostAddress());
        } catch (Exception e) {
            e.printStackTrace();
        }
  }
}

Output

192.168.1.6
Content Protection by DMCA.com
Please Share