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

NOTE (2013-02-09):

For recent versions of Mac OS X, the applet won’t run as is due to changes in Apple’s Java security sandbox model. This may also be true for other systems and browsers. To have this work properly you will need to sign the jar with a code signing certificate.

36 Comments

  1. Joel Lazzari says:

    this applet is worderfull. Great.

    I need to get the serial number of my hard disk – anyone have a idea?

  2. Torquato says:
    Windows Vista returned null, any suggestions? thanks
  3. Tim D says:

    Unfortunately I haven’t tested this on VISTA, but are you sure you have Java version 6 or higher?

  4. Torquato says:
    Yes, the version is correct, the problem and configuration of Vista. Finding the solution I describe.
  5. Torquato says:
    Resolved, the problem in Vista that returns more than one mac, being the first null.
    Changed the source to discard this mac null.

    public static String macToString( …

    if (macAddress.length ()! = 0)
    (
        macAddress.toString return ();
    )

    … }

  6. Brad says:

    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.

  7. Tim D says:

    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.

  8. MGallagher says:

    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

  9. tmth says:

    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.

  10. Guillermo says:

    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

  11. gavin says:

    I need something like this to work in OS X, what would you recommend?

  12. Rizwan says:

    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.

  13. Aden Choe says:

    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.

  14. Chuck says:

    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.

  15. Deny says:

    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

  16. pepe says:

    How I can modify the code for get the complete name adapter network?

  17. Rhodders says:

    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

  18. Rhodders says:

    Can someone also fix it so that it dosent come up with 00:00:00:00:00:00:00:e0 (Windows 7)

  19. ALwarrior says:

    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…

  20. Stephen says:

    Thank you for your applet this program is working fine in IE and Firefox
    I have tested this code in local system and also from a web application, it is working fine.
    But, when i am using JSF project through FacesServlet this code doesn’t work.
    Any suggestion Please…..

  21. Elio Coutinho says:

    Tim, thanks for this code!
    To prevent Vista or 7 from returning those empty or unwanted macs, I changed to this:

    public static String macToString
    (…)
    if (macAddress.length() == 17) {;
    return macAddress.toString();
    }

    Also, confirmed it works on Linux, Mac and 7.

  22. rodrigo f correa says:

    Hello, I’m from Brazil and sorry for my bad
    English. Well there’s some time I am using your applet the
    MacAddressApplet, from which it started to have problems with
    new version of the plugin java 6u22 version, which was up to version 6u21
    operating normally. Looking at the note of this new version of the plugin,
    identified that java has a change in security policy
    regarding direct access to data of the local connection network
    (http://www.oracle.com/technetwork/java/javase/6u22releasenotes-
    176121.html). Do not know if you’ve encountered the problem where it has already
    and can be very grateful if I can report the solution, since
    I need very long feature in my application.

  23. deny says:

    Since Java released version 6 Update 22 applet does not works anymore and return empty string. I have tested on Vista, Win7 and XP and it is needed to update code to make it working.

  24. kk2000 says:

    have any body provide the solution, that can work in version 6 update 22?

  25. Pablo says:

    It works for me, you just need the applet signed for it to work.
    if you are running netbeans: http://www.tek-tips.com/viewthread.cfm?qid=1564833&page=6

  26. pam says:

    What kind of update do the code need? after update JAVA to version 6 Update 22? Can someone tell?

  27. vishnu says:

    thanks a lot…

  28. deny says:

    If we need signed applet for it to work as Pablo said then probably can somebody give us link with signed applet. Pablo do you have link to signed applet? You can upload your signed appled on rapidshare, megaupload, hotfile or similar and then share it with us.

    Thanks

  29. indra says:

    It’s not working. What should I do?

  30. indra says:

    It’s not working.Alert gives blank mac address. What should I do? please help

  31. Lithin says:

    I am not able to run this. I am getting err

    ./build/build.bash: 13: [: GNU/Linux: unexpected operator
    ./build/build.bash: 17: ./build/build.bash: /home/orchid/mac_Addresss/macaddressapplet: Permission denied
    ./build/build.bash: 23: ./build/build.bash: Syntax error: “(” unexpected

    anyone please help me.

    Thanks in Advance.

  32. Andreas Hinderberger says:

    Hello, i’ve used your applet for some time in one of my projects and was very satisfied. With todays update to Java 8u45 i only get a “undefined” back after calling the getmacaddress() function. Any suggestions?

  33. techdetails says:

    I haven’t tested this with Java 8 yet, but the security model changed in JDK 7 and the applet must now have a signed with a valid certificate for work properly

  34. techdetails says:

    The bash script is a cygwin bash script, probably not compatible with linux/OS X.

    If you want I have a Ant build for the project if you’d like.

  35. Andreas Hinderberger says:

    @techdetails:

    applet is seigned with an official code signing cert and following manifest:

    Permissions: all-permissions
    Codebase: *
    Application-Name: CelluPOS

    But it’s not working.

  36. Prithivi says:

    Hi,

    Could i know this will support on Internet, while accessing the web site in client machine. would we able to get the MAC address.

    Advance Thanks,

Leave a Reply