Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find physical machine name in Java

Tags:

java

How can I obtain the physical machine name that my jvm is running in?

(Physical = OS, up to vmware...)

Added from poster's comment:
I mean the name of the computer the JVM is running in. Most likely a physical computer, but if the JVM is running inside another virtual machine then that name is good.

like image 462
ripper234 Avatar asked Jul 08 '09 20:07

ripper234


People also ask

How to get computer name in Java?

We can get the System name for a Windows or Linux machine using the getHostName() method of the InetAddress class of java.net package after getting the IP address of the system using getLocalHost() method of the same class. The class InetAddress gets the IP address of any hostname.

How do I find my hostname in InetAddress?

In Java, you can use InetAddress. getLocalHost() to get the Ip Address of the current Server running the Java app and InetAddress. getHostName() to get Hostname of the current Server name.


1 Answers

String computername=InetAddress.getLocalHost().getHostName(); System.out.println(computername); 
like image 171
jsight Avatar answered Sep 28 '22 17:09

jsight