MAC Address Java Applet
See the link below for source and what is more or less a toy applet to demonstrate sniffing the MAC Address(es) of a machine from the browser. The HTML illustrates the simplest (albeit hackish) approach for cross browser support. I’ve tested this with FF 2.x, IE 5-7 and Safari 3.x on Windows, unfortunately Leopard doesn’t support Java 6 yet. This solution will only work with Java 6, I do no checking in the code for this fact, it’s a demonstration after all.
One thing is for sure, IE treats Java as a third class citizen, I’ve done some timings: FireFox averages 10.5 seconds to start the Java plugin (which is barely acceptable), but IE is terrible with an average startup time of 31.8 seconds this is after clicking through the two levels of dialog about how this applet is insecure and may destroy your system, “oh the humanity” of course this can be turned off, but the default for most folks is to try and scare the pants of you.
You can find the package and source here:
http://www.softwaresamurai.com/Agwego/mac/macaddressapplet-1.0.tar.gz
this applet is worderfull. Great.
I need to get the serial number of my hard disk – anyone have a idea?
Unfortunately I haven’t tested this on VISTA, but are you sure you have Java version 6 or higher?
Changed the source to discard this mac null.
public static String macToString( …
…
if (macAddress.length ()! = 0)
(
macAddress.toString return ();
)
… }
Works super! Ran into the same issue with Vista, but realized right away that it is just the first result and if you return ALL mac addresses, you do get them. Thanks for making this available.
Thanks, this was my prototype app, and indeed if your machine has more than one interface (and the loopback counts) the problem gets a little more complicated. I have a production app in place that ignores the loopback and can deal with multiple interfaces. Unfortunately that wasn’t the app I made available for free use. When I get time I’ll update the app with appropriate code and comments.
Hi! Thanks for the demonstration applet.
I am interested in a more advanced applet possibly similar to the one you said you do NOT offer for free… what is the cost for this one, what are the added features and how do i purchase it?
Cheers,
Mick
I really like this sample. It helped me a lot in my project.
However, getting all available mac addresses only works on windows. From what i gather, java on mac and linux has a limitation where NetworkInterface.getNetworkInterfaces() returns only physically active connection. Is there a work around it?
Thank you very much for sharing this code.
the html don’t work form me in IE7, but works fine in Firefox. IE7 says says that the errors are in these lines:
document.macaddressapplet.setSep( “:” );
document.macaddressapplet.setFormat( “%02x” );
var macs = eval( String( document.macaddressapplet.getMacAddressesJSON() ) );
the message from IE7: the object don’t accept this method
thanks for any help
I need something like this to work in OS X, what would you recommend?
This applet works fine in XP OS but it doesnot work in vista. I tried the code that you have given for vista but still i dont get any MAC address. Can you help. Thanks in advance.
Hi!
Thank you for your applet.
But I have one question. The question is First mac address is just macaddress of localhost?
Please answer me.
Thank you.
Can this output to a vairable instead of a JavaScript alert?
I need a way to get a computer’s IP Address, Hostname, and MAC Address so that I can place the contents of these items into a “mailto” tag so my LAN users can request access to blocked websites. This information would make it easy for them to request a webpage to be unblocked. This would need to work for Apple and Windows computers.
Great applet but can someone fix code for Get “first” MAC Address ” because it does not display any result on Vista. Not with Firefox neither with IE.
Thanks
How I can modify the code for get the complete name adapter network?
Can someone sort out the Get “first” MAC Address ” as mentioned in the above posts, and then post a link, it would be much appreciated by all
Can someone also fix it so that it dosent come up with 00:00:00:00:00:00:00:e0 (Windows 7)
macs[ 0 ]; Contain Windows XP mac address.
macs[ 1 ]; Contain the first mac of Vista and Seven.
You can try this:
if(macs[ 0 ])mac_string += macs[ 0 ];
if(macs[ 1 ])mac_string += macs[ 1 ];
Then filter or import only first 17 characters…