Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get Machine name

 
Raul Quintero
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there's probably an easier way, but take a look at getLocalHost
java.net.InetAddress. you can then use getHostName.
 
Raul Quintero
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raul Quintero
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic