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

Reading MAC address

 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Is there any way to read MAC address of the ethernet card. My requirement is to enable & disable the ethernet card programatically. If java does not support then some C code and JNI will also solve my problem.
Please give me some solution.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In pure Java - impossible. Another language (C and Windows API?) and JNI are the way to go here without a doubt.
 
Mark Wuest
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can run an external program and parse the output.

In Linux, the program is "/sbin/ifconfig <interface>" - the number after HWaddr is the MAC address. e.g.:

In the example above, 00:0A:E6:CF:ED:B4 is the MAC address.

In Windows, the command is "ipconfig /all" and the line with Physical Address in it has your MAC address. The line will look somewhat like this:


You'd run it like this in Linux:

then read and parse 'in' for your answer.

Mark
[ June 04, 2005: Message edited by: Mark Wuest ]
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep in mind it is possible for a computer to have more than one MAC address.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And possible to fake MAC-Adresses.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic