There's no universal concept of a computer name across OSes, but DNS is generally available. If the computer name hasn't been configured so DNS can resolve it, it isn't available.
String hostname = "Unknown";
try
{
InetAddress addr;
addr = InetAddress.getLocalHost();
hostname = addr.getHostName();
}
catch (UnknownHostException ex)
{
System.out.println("Hostname can not be resolved");
}
cmd : ipconfig
2 How to get Ip address using java
Enumeration e=NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements())
{
NetworkInterface n=(NetworkInterface) e.nextElement();
Enumeration ee = n.getInetAddresses();
while(ee.hasMoreElements())
{
InetAddress i= (InetAddress) ee.nextElement();
System.out.println(i.getHostAddress());
}
}
http://stackoverflow.com/questions/9481865/how-to-get-ip-address-of-our-own-system-using-java
Last edit: Yiyang Pan 2014-02-01
3 How to get computer name using java
There's no universal concept of a computer name across OSes, but DNS is generally available. If the computer name hasn't been configured so DNS can resolve it, it isn't available.
String hostname = "Unknown";
try
{
InetAddress addr;
addr = InetAddress.getLocalHost();
hostname = addr.getHostName();
}
catch (UnknownHostException ex)
{
System.out.println("Hostname can not be resolved");
}
http://stackoverflow.com/questions/7883542/getting-the-computer-name-in-java