permaculture playing cards*
The moose likes Beginning Java and the fly likes How to get Machine name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get Machine name" Watch "How to get Machine name" New topic
Author

How to get Machine name

Raul Quintero
Greenhorn

Joined: Feb 18, 2000
Posts: 7
Hello all. Can anyone tell me how I would get the name of a machine that java is executing on? I cannot seem to figure out which property holds that info.
Raul
Fred Hosch
Author
Greenhorn

Joined: Apr 16, 2001
Posts: 23
there's probably an easier way, but take a look at getLocalHost
java.net.InetAddress. you can then use getHostName.


Fred Hosch<br />Author of:<br /><a href="http://www.amazon.com/exec/obidos/ASIN/0471354899/ref=ase_electricporkchop/107-7882751-0234939" target="_blank" rel="nofollow">An Introduction to Software Construction with Java</a>
Raul Quintero
Greenhorn

Joined: Feb 18, 2000
Posts: 7
Thanks for the suggestion. However, this is going to be an internal running program, so I'm not sure if I will be able to use that route.
Any other suggestions?
Raul
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
So what exactly do you mean by "name"? The IP address of the machine? The Mac address of the machine? The brand of machine? The operating system that is running on the machine?
Just knowing that I call my machine bimbo and that it is an IBM is not useful information.
If you look in System.getProperties() there is a list of the things that are available (and meaningful) that are java related.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I'm a little puzzled - what do you mean by "an internal running program"? The method outlined above is the usual way of getting the machine name. I have a hard time envisioning a situation where the concept of a "machine name" makes sense but this call is not available.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Raul Quintero
Greenhorn

Joined: Feb 18, 2000
Posts: 7
Hey guys, sorry if I'm so unclear. Basically, I need to get the name of the server that this program will be running on. In a windows example, if you go into network neighborhood and you see the list of machine names, I need to get that name for that server that's running the app. So if the server is named Bimbo on the network, then I need my file to have Bimbo in there. This neccesarilly isn't an Internet, or networked application, and the machine running it might not have http in it's protocols list, so I'm unclear if I can use the getHostName method. If I can, then I stand corrected.
I also went through the list of properties that java sends back and none had what I need. I don't care about OS name, and user dir and such.
If this doesn't make sense as to why anyone would want this info, is is used to create log files, and that's what the user wants.
Thanks again,
and I hope I didn't confuse you guys any further.
Raul
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get Machine name