HOME - Recent Changes - Search:

Academic Work


Personal

* pot de départ


dblp


(:twitter:)

-----

[ edit | logout ]
[ help | sandbox | passwd ]

Extract the MAC address

#############################

Problem

You want a portable Java solution for extracting the MAC address.

Update

I sent the patch below to Johann and he added this feature to version 3.2. So with new version you can get the MAC address easily.

Solution

Johann Burkard made a freely available package for generating UUIDs (or GUIDs) in Java. For this, he needs to extract the MAC address but unfortunately he doesn't provide a getMacAddress() function. So here is my simple modification:

In UUIDGen.java:

private static String macAddress = null;    // new

public static String getMacAddress() {    // new
    return macAddress;
}

static {

//    String macAddress = null;   // put to remark

    // from here unchanged
    try {
        Class.forName("java.net.InterfaceAddress");
        macAddress = Class.forName("com.eaio.uuid.UUIDGen$HardwareAddressLookup").newInstance().toString();
    }

I sent Johann a mail, hopefully it'll be added in a future release. Update: Johann promised to put it in version 3.2 :)

Usage:

String macAddress = UUIDGen.getMacAddress();
System.out.println(macAddress);

More info

See http://en.wikipedia.org/wiki/Mac_address for more info. The important stuff is that a MAC address is 6 bytes long, i.e. 48 bits.

Hex String to int conversion

The following example is from http://mindprod.com/jgloss/hex.html:

/* convert a hex String to int */
// Note, there is no lead 0x, case insensitive
String g = "af0c99";
int i = Integer.parseInt( g.trim(), 16 /* radix */ );

For more info on conversions, refer to http://mindprod.com/jgloss/hex.html .

Cloud City


anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows


Blogs and Dev.

* Ubuntu Incident
* Python Adventures
* me @ GitHub


Places

Debrecen | France | Hungary | Montreal | Nancy


Notes

full circle | km


Hobby Projects

* Jabba's Codes
* PmWiki
* Firefox
* PHP
* JavaScript
* Scriptorium
* Tutorials
* me @ GitHub


Quick Links


[ edit ]

View - Edit - History - Attach - Print *** Report - Recent Changes - Search
Page last modified on 2010 April 23, 15:45