1

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
1

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

Comments

1

Try the following code:

System.out.println(java.net.InetAddress.getLocalHost().getHostName());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.