• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get mac address

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i get the local machine's MAC address?
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Edwin,

thanks, it helps.
 
reply
    Bookmark Topic Watch Topic
  • New Topic