The InetAddress class This class represents an Internet Protocol (IP) address. You can get the local IP Address & Hostname of the system using getLocalAddress() method of this class
import java.net.InetAddress; public class GetIpAddress { public static void main(String args[]) throws Exception{ InetAddress addr = InetAddress.getLocalHost(); System.out.println("Local HostAddress: "+addr.getHostAddress()); String hostname = addr.getHostName(); System.out.println("Local host name: "+hostname); } }
Local HostAddress: 192.168.25.1 Local host name: Tutorialspoint