I need to get the hostId of my server using a Java program. Is there something in the Java API that is built-in which can help me do this?
lab.com$ hostid
f9y7777j -> How can I get this using java
I need to get the hostId of my server using a Java program. Is there something in the Java API that is built-in which can help me do this?
lab.com$ hostid
f9y7777j -> How can I get this using java
The following would allow you to run a console command and store the result:-
ProcessBuilder pb = new ProcessBuilder("hostid");
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null)
{
// Store returned string here.
}
reader.close();
Try the following code:
System.out.println(java.net.InetAddress.getLocalHost().getHostName());