Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

get my computer hostid  RSS feed

 
Nils Briard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
is it possible to get my hostid in Java and how do I do this ?
thx
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch!
If by "hostid" you mean the local ip address, then
use the static method java.net.InetAddress.getLocalHost() to get an InetAddress object representing the local machine; you can then use the various methods of that class to get the info in the format you want.
If you mean what the Unix "hostid" program returns, I don't think there's a Java equivalent.
 
Nils Briard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Welcome to Java Ranch!

Thank you Ernest

If you mean what the Unix "hostid" program returns, I don't think there's a Java equivalent.

That's exactly what I'd like to get but on Windows OS...
Maybe I should use JNI to do so ? or anything else ?
Nils
 
Nils Briard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
If I use JNI to get the Mac Address, which DLL and which method I should call to do this ?
Regards
Nils
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't tell you anything about Windows DLLs; I've been proudly Microsoft free for years. Googling "Java mac address" gives several links to presumably working code where people run "ipconfig" or "arp -a" (on Unix) and parse out a MAC address from there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!