IP Address And HostName Of Local Computer In Java
Chapter:
Networking
Last Updated:
30-04-2016 19:07:57 UTC
Program:
/* ............... START ............... */
import java.net.InetAddress;
public class JavaIPAndHostNameOfLocalSystem {
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);
}
}
/* ............... END ............... */
Output
Local HostAddress: 192.168.1.108
Local host name: JavaScan-PC
Tags
IP Address And HostName Of Local Computer, Java, Networking