aspose file tools*
The moose likes Java in General and the fly likes how to get mac address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to get mac address" Watch "how to get mac address" New topic
Author

how to get mac address

lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
How can i get the local machine's MAC address?
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
If you're running JSE6:

NetworkInterface.getHardwareAddress()

If you're running an earlier JVM, there is no pure Java solution. You could do something like this on Linux:

Runtime.getRuntime().exec("/sbin/ifconfig");

and parse the output.

or on Windows:

Runtime.getRuntime().exec("cmd.exe -c ipconfig -all");
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i am working on windows and my jdk is 1.4. If i would llike to use JNI, how should i go about it.

I have try the code NetworkInterface.getHardwareAddress(), but it return me an error saying cannot resolve symbol, getHardwareAddress()


if i using this code:
Runtime.getRuntime().exec("cmd.exe -c ipconfig -all");

how to get the MAC address. I have done a system.out.print for the statement, i.e. System.out.println(Runtime.getRuntime().exec("cmd.exe -c ipconfig -all").toString());

i get the result as "java.lang.Win32Process@194df86"


[ December 19, 2006: Message edited by: lynn fann ]
[ December 19, 2006: Message edited by: lynn fann ]
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
The Runtime.exec(String) method returns a java.lang.Process object. Use that object to get an InputStream and obtain console results.

For instance:



I hope that helps!
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
hi Edwin,

thanks, it helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get mac address